【问题标题】:Swift: Action if the user accepted or rejected notificationsSwift:用户接受或拒绝通知时的操作
【发布时间】:2017-03-19 23:26:57
【问题描述】:

我正在使用以下代码请求推送和本地通知权限:

let application = UIApplication.shared
let settings: UIUserNotificationSettings = UIUserNotificationSettings( types:  [.alert, .badge, .sound], categories: nil )

application.registerUserNotificationSettings( settings )
application.registerForRemoteNotifications()

在我采取行动之前,我需要等待用户接受或拒绝通知。我怎样才能做到这一点?

【问题讨论】:

  • 查看UIApplicationDelegate的文档。

标签: ios swift nsusernotification


【解决方案1】:

注意:Apple 已经弃用了我在下面给出的答案。请参阅@ergunkocak 的回答

当用户授予或拒绝权限时,应用委托中的回调方法是application(_:didRegister:),这是您应该根据用户选择的权限设置执行特定操作的方法。我建议阅读文档here.

【讨论】:

    【解决方案2】:

    AppDelegate.swift 中的 Swift 3:

    func application(_ application: UIApplication, didRegister notificationSettings: UIUserNotificationSettings) {
        // Check here
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多