本地通知在 iOS 10.3.1 中不起作用
Local Notification not working in iOS 10.3.1
我有一个应用程序,它会在应用程序是否处于后台时发送特定位置更改的本地通知运行。我正在使用区域监控来获取位置变化并在需要时创建通知请求。我的问题是通知在 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")
}
}
iOS10 是否有我遗漏的必须包含的内容?为什么它不能单独在 iOS 10 中工作?
在堆栈溢出上花了几个小时后,多亏了另一个 post 中的这个 。我们还应该提到content.body
。这在 iOS 10 中不应为空。由于某种原因,通知在 iOS 11 和 12 中没有正文。
我有一个应用程序,它会在应用程序是否处于后台时发送特定位置更改的本地通知运行。我正在使用区域监控来获取位置变化并在需要时创建通知请求。我的问题是通知在 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")
}
}
iOS10 是否有我遗漏的必须包含的内容?为什么它不能单独在 iOS 10 中工作?
在堆栈溢出上花了几个小时后,多亏了另一个 post 中的这个 content.body
。这在 iOS 10 中不应为空。由于某种原因,通知在 iOS 11 和 12 中没有正文。