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

时间:2014-11-03 15:50:27

标签: ios notifications ios8

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

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

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

3 个答案:

答案 0 :(得分: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];
  }
}

对于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
}

答案 1 :(得分:1)

首先,您必须注册使用本地推送通知

UIApplication *application = [UIApplication sharedApplication];
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
    [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
}

然后你可以发送本地推送通知

 UILocalNotification *notification = [UILocalNotification new];
notification.alertBody = @"Local Push !!!";
notification.applicationIconBadgeNumber=1;
[[UIApplication sharedApplication] presentLocalNotificationNow:notification];

答案 2 :(得分:0)

void EnableLocalNotificationIOS8
{
    UIApplication *app = [UIApplication sharedApplication];

    if ([app respondsToSelector:@selector(registerUserNotificationSettings:)])
    {
        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
        [app registerUserNotificationSettings:settings];
        [app registerForRemoteNotifications];
    }
}