【问题标题】:get ios push deviceToken second time第二次获取ios push deviceToken
【发布时间】:2014-11-10 01:34:37
【问题描述】:

我需要获取 deviceToken。 当我向我的应用添加推送通知时,我通过didRegisterForRemoteNotificationsWithDeviceToken 收到了 deviceToken

但现在我需要再次获取它,但我没有保存。 didRegisterForRemoteNotificationsWithDeviceToken 只调用一次,其他时候应用只运行 registerUserNotificationSettings

我想将所有新用户的令牌保存到[NSUserDefaults standardUserDefaults],但它只适用于新用户。如何处理现有用户?

【问题讨论】:

    标签: ios xcode notifications push devicetoken


    【解决方案1】:

    在“didFinishLaunchingWithOptions”方法中添加如下代码……

    if ([application respondsToSelector:@selector(registerUserNotificationSettings:)])
    {
        [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
        [[UIApplication sharedApplication] registerForRemoteNotifications];
    } 
    else
    {
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
         (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
    }
    

    然后在应用启动过程中,每次调用“didFinishLaunchingWithOptions”都会调用“didRegisterForRemoteNotificationsWithDeviceToken”方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-06
      • 2023-03-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多