【发布时间】:2019-04-08 10:20:36
【问题描述】:
我有一个应用程序,它会在应用程序处于后台或未运行时发送特定位置更改的本地通知。我使用区域监控来获取位置更改并在需要时创建通知请求。我的问题是通知在 iOS 10 中无法正常工作,而在 iOS 11 和 12 中可以正常工作。下面是创建通知请求的代码。
func getRequest() {
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound]) { (granted, error) in
if granted {
DispatchQueue.main.async {
self.scheduleNotification()
}
}
}
}
func scheduleNotification() {
let timeTrigger = UNTimeIntervalNotificationTrigger.init(timeInterval: 15.0, repeats: false)
let center = UNUserNotificationCenter.current()
let content = UNMutableNotificationContent.init()
content.title = "Notification works!"
content.sound = UNNotificationSound.default
let request = UNNotificationRequest.init(identifier: "LocalNotification", content: content, trigger: timeTrigger)
center.add(request) { (error) in
print(error?.localizedDescription ?? "No Error")
}
}
这里有什么我想念的东西必须包含在 iOS 10 中吗?为什么它不能单独在 iOS 10 中运行?
【问题讨论】:
标签: ios unusernotificationcenter unnotificationtrigger