我在视图控制器按钮操作中有以下代码:
- (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];
}
}
Run Code Online (Sandbox Code Playgroud)
注册完成后,didBecomeActive会发布通知,我正在检查用户做了什么:
-(void)didBecomeActive:(NSNotification *)notification
{
if([[UIApplication sharedApplication] enabledRemoteNotificationTypes] == UIRemoteNotificationTypeNone){
// if user decline
}
} else {
// if user accept
}
Run Code Online (Sandbox Code Playgroud)
所以我的问题是:如果用户拒绝接收推送通知并稍后决定启用它们(设置 - >通知中心 - >我的应用程序),则会出现一个惊喜:设置中启用了"警报","徽章"和"声音" ,但应用程序返回 UIRemoteNotificationTypeNone.
有什么想法有什么不对?
注:我知道这些方法现在已经过时,所以请不要告诉我用registerForRemoteNotifications:和UIUserNotificationSettings,它已经完成.