本地通知不适用于某些用户(iOS 8)

Mik*_*sya 9 notifications ios ios8

我有一个使用本地通知的应用程序,并且在以前的版本中使用了ti.我已经更新了iOS 8的应用程序并进行了测试并且运行良好.在向app store提交更新后,少数用户抱怨他们没有收到任何本地通知.但是,我检查过的用户数量较多,没有任何问题.

对于有错误的用户(至少其中一个),他们无法在"设置 - > myApp"屏幕中看到"通知"项目; 缺少整个选项而不是禁用它."位置"和"使用蜂窝数据"在该屏幕中,但不在通知中.我试图更改"设置 - >通知 - > myApp"下的设置,它按预期工作.

有关如何调试此问题的任何建议都将非常有用.谢谢!

Nag*_*jun 8

试试Objective-C:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:    (NSDictionary *)launchOptions
{
// are you running on iOS8?
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) 
  {
    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge|UIUserNotificationTypeAlert|UIUserNotificationTypeSound) categories:nil];
    [application registerUserNotificationSettings:settings];
  } 
else // iOS 7 or earlier
  {
    UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
    [application registerForRemoteNotificationTypes:myTypes];
  }
}
Run Code Online (Sandbox Code Playgroud)

对于Swift:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
// Override point for customization after application launch.
 if(UIApplication.instancesRespondToSelector(Selector("registerUserNotificationSettings:")))
 {
    application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: UIUserNotificationType.Sound | UIUserNotificationType.Alert | UIUserNotificationType.Badge, categories: nil))
 }
 else
 {
    //
 }
return true
}
Run Code Online (Sandbox Code Playgroud)

  • 谢谢.我选择这个作为正确的答案,因为这是第一个回答.在发布这些答案之前,我已经实现了相同的代码(registerUserNotificationSettings),并要求我的一个用户使用Ad-hoc测试进行测试,并确认问题已解决.**在iOS 8中,还需要注册本地通知**. (2认同)