0

I can't test this code properly until later tonight, but to avoid some mistake beforehand, can this be used to turn on and off notification? The NSUserDefault is from a switch statement and should be self explanatory. Does registering and unregistering mimic what the iOS setting push notification switch does (turn notification on and off)?

-(void)notification{
   if ([[NSUserDefaults standardUserDefaults] boolForKey:@"Switch"]) {
      [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
   }
   if (![[NSUserDefaults standardUserDefaults] boolForKey:@"Switch"]) {
      [[UIApplication sharedApplication]unregisterForRemoteNotifications];   
   }    
}
Ben D
  • 14,321
  • 3
  • 45
  • 59
Joe Aikman
  • 125
  • 1
  • 1
  • 5
  • No, the iOS settings in the Notifications area only change the actions the system takes once the notification comes into the device, but for apps the best thing to do is to tell your server wether to send notifications or not... – jjv360 Mar 28 '13 at 13:35
  • see SO Answer http://stackoverflow.com/questions/10493949/enable-disable-apple-push-notification-from-iphone-app – Deepesh Mar 28 '13 at 13:54

0 Answers0