如何检查是否已单击 "Ask for push notifications" 权限警报

How to check if "Ask for push notifications" permission alert has been clicked on

如何检查用户是否以及何时对此视图进行操作?

我想这样做:

if notificationviewclosed{
    dosomething
}

但是我想不出一个合适的方法来检查这个。这是我的代码:

func SetupPushNotifications(){

    // Register for Push Notitications
    var userNotificationTypes:UIUserNotificationType = (UIUserNotificationType.Alert |
        UIUserNotificationType.Badge |
        UIUserNotificationType.Sound)

    if UIApplication.sharedApplication().respondsToSelector("isRegisteredForRemoteNotifications"){ //this should be done with getobjc method
        // iOS 8 Notifications
        var settings:UIUserNotificationSettings = UIUserNotificationSettings(forTypes: userNotificationTypes, categories: nil)
        UIApplication.sharedApplication().registerUserNotificationSettings(settings)
        UIApplication.sharedApplication().registerForRemoteNotifications()
    }else{
        // iOS < 8 Notifications
        UIApplication.sharedApplication().registerForRemoteNotificationTypes(.Badge | .Sound | .Alert)
    }
}

您可以通过在 AppDelegate 中实现以下两种方法来处理用户对提示的响应。

对于iOS8:

     func application(_ application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings)

对于 < iOS8:

     func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData)

在此方法中,您可以通过调用以下命令并检查值

来检查用户是否已授予权限
application.enabledRemoteNotificationTypes()

查看此处了解更多信息: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/index.html#//apple_ref/occ/intfm/UIApplicationDelegate/application:didRegisterUserNotificationSettings