相关疑难解决方法(0)

在ios10中添加本地通知 - swift 3

编辑:所以把应用程序放在后台就行了.

原版的:

所以我一直在尝试向新的UNUserNotificationCenter添加通知,但我似乎没有得到它.

我的视图控制器有一个动作:

@IBAction func sendPressed(_ sender: AnyObject) {
    let content = UNMutableNotificationContent()

    content.title = "Hello"
    content.body = "What up?"
    content.sound = UNNotificationSound.default()

    // Deliver the notification in five seconds.
    let trigger = UNTimeIntervalNotificationTrigger.init(timeInterval: 5, repeats: false)
    let request = UNNotificationRequest.init(identifier: "FiveSecond", content: content, trigger: trigger)

    // Schedule the notification.
    let center = UNUserNotificationCenter.current()
    center.add(request) { (error) in
        print(error)
    }
    print("should have been added")
}

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)

    let center = UNUserNotificationCenter.current()
    center.requestAuthorization([.alert, .sound]) { …
Run Code Online (Sandbox Code Playgroud)

uilocalnotification swift swift3 ios10 unusernotificationcenter

27
推荐指数
2
解决办法
5万
查看次数