What is the Callback Method if You Click “Don't Allow” in Push Notification Popup? [duplicate]

只愿长相守 提交于 2020-01-03 17:27:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!