我有一个应用程序,当应用程序处于后台或未运行时,它将针对特定位置更改发送本地通知。我使用区域监控来获取位置更改并在需要时创建通知请求。我的问题是通知在 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 中运行?