Push notifications on/off settings

- (void)notificationsChangedWithStatus:(BOOL)status { if (status) { if ([[UIApplication sharedApplication]respondsToSelector:@selector(isRegisteredForRemoteNotifications)]) { // iOS 8 Notifications [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]]; [[UIApplication sharedApplication] registerForRemoteNotifications]; } else { // iOS < 8 Notifications [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)]; } } else { [[UIApplication sharedApplication] unregisterForRemoteNotifications]; } [[NSUserDefaults standardUserDefaults] setBool:status forKey:kPushSettings]; }
Usefull for a switch to turn on/off the notifications

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.