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];
}
}