小编Sim*_*pic的帖子

iOS 10 本地通知未显示

我一直致力于在 iOS 10 中为我的应用程序设置本地通知,但在模拟器中测试时,我发现通知可以成功安排,但在安排的时间到来时永远不会真正出现。这是我一直在使用的代码:

let UNcenter = UNUserNotificationCenter.current()
        UNcenter.requestAuthorization(options: [.alert, .badge, .sound]) { (granted, error) in
            // Enable or disable features based on authorization

            if granted == true {

                self.testNotification()


            }

        }
Run Code Online (Sandbox Code Playgroud)

然后它运行此代码(假设日期/时间是将来的时间):

func testNotification () {
    let date = NSDateComponents()


    date.hour = 16
    date.minute = 06
    date.second = 00
    date.day = 26
    date.month = 1
    date.year = 2017

    let trigger = UNCalendarNotificationTrigger(dateMatching: date as DateComponents, repeats: false)

    let content = UNMutableNotificationContent()
    content.title = "TestTitle"
    content.body = "TestBody"
    content.subtitle = …
Run Code Online (Sandbox Code Playgroud)

notifications swift3 ios10 ios10.2

5
推荐指数
1
解决办法
5319
查看次数

标签 统计

ios10 ×1

ios10.2 ×1

notifications ×1

swift3 ×1