如何解决在 iOS 14.6 中实施本地严重警报?
Apple 已批准我申请使用严重警报的权利。我将我的权利附加到我的包标识符并创建了一个配置文件并根据 Apple 的说明手动签署了我的应用程序:https://help.apple.com/developer-account/#/dev38c81d4cd
我还添加了一个 properties.entitlements 文件,其中包含正确修改的包标识符和布尔值“YES”。我的“构建设置”在“签名”中没有“代码签名权利”。
当我运行下面的代码时,我收到接受警报的提示,但没有出现严重警报。有什么建议么?谢谢!
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
var authOptions: UNAuthorizationOptions?
if #available(iOS 12.0,*) {
authOptions = [.alert,.badge,.sound,.criticalAlert]
} else {
authOptions = [.alert,.sound]
}
UNUserNotificationCenter.current().requestAuthorization(options:
authOptions!) { (granted,error) in
if !granted {
print("The application requires Notifications permission to display push notifications. Please enable it in settings.")
} else {
let userNotificationCenter = UNUserNotificationCenter.current()
var contentTitle:String?
var contentMessage:String?
var contentSound:UNNotificationSound?
contentTitle = "Message:"
contentMessage = "Critical Alert!"
contentSound = .defaultCritical
let content = UNMutableNotificationContent()
content.title = contentTitle!
content.subtitle = contentMessage!
content.sound = contentSound
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1,repeats: false)
let request = UNNotificationRequest(identifier: UUID().uuidString,content: content,trigger: trigger)
userNotificationCenter.add(request)
}
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。