问题
During the testing of remote push notifications in my App I faced some strange behavior:
I keep getting notifications even if I turn off the "notifications enabled" for my application option in settings App. Is that normal? Should my App unsubscribe from getting notifications itself after disabling that option, or it is response of iOS? Or should I do something special when registering for remote notifications? Or maybe its normal for "sandbox" notifications?
Tested on iOS 5.1 on iPhone 4.
回答1:
The UI for disabling notifications is confusing, I think. Switching 'Notification Centre' to OFF is not the same as disabling notifications.
You all need to deselect the 'Alert Style', the 'Badge App Icon', 'Sounds', and 'View in Lock Screen - all individually.
Here's the code I use to examine the notification settings at run-time:
UIRemoteNotificationType notificationSelection = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
BOOL sendMessage;
if (notificationSelection == UIRemoteNotificationTypeNone)
{
NSLog(@"Push Notifications : DISABLED (%0X)!", notificationSelection);
sendMessage = NO;
}
else
{
NSLog(@"Push Notifications : ENABLED (%0X) - hurrah! :-)", notificationSelection);
if (notificationSelection & UIRemoteNotificationTypeBadge)
{
NSLog (@"Push Notifications : Badge");
}
if (notificationSelection & UIRemoteNotificationTypeSound)
{
NSLog (@"Push Notifications : Sound");
}
if (notificationSelection & UIRemoteNotificationTypeAlert)
{
NSLog (@"Push Notifications : Alert");
}
if (notificationSelection & UIRemoteNotificationTypeNewsstandContentAvailability)
{
NSLog (@"Push Notifications : Newstand Content Availability");
}
}
来源:https://stackoverflow.com/questions/12299393/keep-receiving-ios-push-notifications-after-disabling-them-in-settings-app