How to check if the "Request push notifications" button was clicked
How can I check if a user has performed an action in this view?
I want to do this:
if notificationviewclosed{
dosomething
}
However, I couldn't find a decent way to test this. Here is my code:
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)
}
}
+3
source to share
1 answer
You can handle the user's response to the request by executing both methods in the AppDelegate.
For iOS8:
func application(_ application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings)
For <iOS8:
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData)
In this method, you can check if the user has granted permission by calling the following and checking the value
application.enabledRemoteNotificationTypes()
See here for more information: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/index.html#//apple_ref/occ/intfm/UIApplicationDelegate/application:didRegisterUserNotificationSettings
+3
source to share