问题
There's a push notification popup that appears on fresh install of app. There are two choices, OK and Don't Allow (if i remember it correctly.)
I want to know what's the call back method if I click "Don't Allow". The thing is, I implemented didFailToRegisterForRemoteNotifications because I thought that if I click "Don't Allow" it would go straight to that method in AppDelegate. However, the method wasn't called.
My problem is I need to know the event when user clicks on "Don't Allow". Is there a way to do this? I'd appreciate any help. Thanks.
回答1:
There is no delegate callback however from here:Callback Method if user declines Push Notification Prompt?
You can have a BOOL variable to check it in your AppDelegate,
AppDelegate.m
// declare a BOOL
BOOL allow = NO;
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
allow = YES;
[self doWhatever];
}
- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{
allow = YES;
[self doWhatever];
}
回答2:
didFailToRegisterForRemoteNotifications
is when communication with apple registration service fail, there is no way to know a user just clicked on don't allow, but you can check UIApplication, there is a method to know the state of PushNotification registration
NSUInteger rntypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
if (rntypes == UIRemoteNotificationTypeNote) {
// application is not registered for any type of push notification
}
来源:https://stackoverflow.com/questions/19704501/what-is-the-callback-method-if-you-click-dont-allow-in-push-notification-popu