【问题标题】:Local Notification not working in iOS 10.3.1本地通知在 iOS 10.3.1 中不起作用
【发布时间】: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


    【解决方案1】:

    在堆栈溢出上花费了几个小时后,感谢answer 在另一篇文章中。我们还应该提到content.body。这在 iOS 10 中不应为空。由于某种原因,通知在 iOS 11 和 12 中没有正文。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-10
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      • 2020-06-30
      • 1970-01-01
      • 2020-09-22
      相关资源
      最近更新 更多