我在视图控制器按钮操作中有以下代码:
- (IBAction)requestPermissions:(id)sender { DDLogInfo(@"Start permission requesting."); if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerForRemoteNotifications)]){ [[UIApplication sharedApplication] registerForRemoteNotifications]; } else { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didBecomeActive:) name:UIApplicationDidBecomeActiveNotification object:nil]; [[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound]; } }
-(void)didBecomeActive:(NSNotification *)notification { if([[UIApplication sharedApplication] enabledRemoteNotificationTypes] == UIRemoteNotificationTypeNone){ // if user decline } } else { // if user accept }
所以我的问题是:如果用户拒绝接收推送通知并稍后决定启用它们(设置 – >通知中心 – >我的应用程序),则会出现意外:启用“警报”,“徽章”和“声音”在“设置”中,但应用程序返回UIRemoteNotificationTypeNone.
有什么想法有什么不对?
注意:我知道这些方法已被弃用,所以请不要告诉我使用registerForRemoteNotifications:和UIUserNotificationSettings,它已经完成了.