首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >更新到swift 4后,UNUserNotification不起作用

更新到swift 4后,UNUserNotification不起作用
EN

Stack Overflow用户
提问于 2017-10-18 22:19:16
回答 1查看 397关注 0票数 0

所以我有一个交互式推送通知,但它突然停止工作,这是我的代码:

代码语言:javascript
复制
func pushNotification(){
    let content = UNMutableNotificationContent()
    let answer1 = UNNotificationAction(identifier: "answer1", title: "thank you!", options: UNNotificationActionOptions.foreground)

    let category = UNNotificationCategory(identifier: "myCategory", actions: [answer1, answer2], intentIdentifiers: [], options: [])
    UNUserNotificationCenter.current().setNotificationCategories([category])
    content.sound = UNNotificationSound.default()
    //Created notification
    content.body = "how are you?"
    content.categoryIdentifier = "myCategory"
    content.badge = 1
    let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 10, repeats: false)
    let request = UNNotificationRequest(identifier: "timerDone", content: content, trigger: trigger)
    UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)
}



@objc(userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:) func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void)
    {

        if response.actionIdentifier == "answer1"
        {
            print("ok")
            performSegue(withIdentifier: "FastResult", sender: self)
        }

        completionHandler()
    }

当我运行应用程序时,我收到了通知,但没有收到输出:"ok“,并且没有segue。

EN

回答 1

Stack Overflow用户

发布于 2017-10-19 00:57:16

只有当你点击“response.actionIdentifier ==”时,"answer1“才是真的。通知中的选项。如果你只是点击通知,那就不是真的。请查收

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46812413

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档