Reputation: 39181
How to check if and when the user makes an action on this view?
I want to do this:
if notificationviewclosed{
dosomething
}
However I couldn't figure out a decent way to check 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)
}
}
Upvotes: 3
Views: 1935
Reputation: 1550
You can handle the users response to the prompt by implementing both of the following methods in your 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 given permission by calling the following and checking the value
application.enabledRemoteNotificationTypes()
See here for more info: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/index.html#//apple_ref/occ/intfm/UIApplicationDelegate/application:didRegisterUserNotificationSettings
Upvotes: 3