简体   繁体   English

iOS7-enabledRemoteNotificationTypes返回UIRemoteNotificationTypeNone,但在Settings.app Alert中,启用了Badge和Sound

[英]iOS7 - enabledRemoteNotificationTypes return UIRemoteNotificationTypeNone but in Settings.app Alert,Badge and Sound are enabled

I have following code in view controller button action: 我在视图控制器按钮操作中有以下代码:

- (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];
  }
}

After registration is finished didBecomeActive notification is posted and I'm making a check what user have done: 注册完成后, didBecomeActive通知将发布,我正在检查用户的操作:

-(void)didBecomeActive:(NSNotification *)notification
{
   if([[UIApplication sharedApplication] enabledRemoteNotificationTypes] == UIRemoteNotificationTypeNone){
// if user decline 
}
} else {
 // if user accept
}

So my problem is: If user decline to receive push notifications and later decides to enable them (Settings->Notification center->My App), there is a surprise: 'Alert' ,'Badge' and 'Sound' are enabled in Settings, but app returns UIRemoteNotificationTypeNone . 所以我的问题是:如果用户拒绝接收推送通知,后来又决定启用它们(“设置”->“通知中心”->“我的应用”),则会出现一个意外:“设置”中启用了“警报”,“徽章”和“声音”但应用程式会传回UIRemoteNotificationTypeNone

Any ideas what is wrong? 任何想法有什么问题吗?

Note: I know these methods are deprecated, so please don't tell me to use registerForRemoteNotifications: and UIUserNotificationSettings , it is already done. 注意:我知道这些方法已被弃用,所以请不要告诉我使用registerForRemoteNotifications:UIUserNotificationSettings ,它已经完成了。

Well, possibly it returns a proper value after app restart, could you check that? 好吧,它可能会在应用重启后返回正确的值,您能检查一下吗? I've found situations where iOS automatically kills your app when changing permissions in Settings while your app is in the background, fe Photos feed access; 我发现有些情况,当您的应用程序在后台运行时,在“设置”中更改权限时,iOS会自动杀死您的应用程序,例如,照片供稿访问权限; I suppose it's just a buggy implementation in iOS in this case, this wouldn't surprise me. 我想在这种情况下,它只是iOS中的一个错误实现,这不足为奇。 I think I've hitted this situation you describe as well, and after finding it's returning invalid/old values until restart, I gave up and make the flow count with required restart. 我想我也遇到了您描述的这种情况,在发现它返回无效/旧值直到重启之前,我放弃了,并按要求的重启进行了流量计数。

Anyway, I don't think there's anything you could do about it. 无论如何,我认为您对此无能为力。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM