1

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

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

我想将所有新用户的令牌保存到,[NSUserDefaults standardUserDefaults]但它只适用于新用户。现有用户怎么办?

4

1 回答 1

1

在“didFinishLaunchingWithOptions”方法中添加以下代码……</p>

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”方法。

于 2014-11-10T05:38:00.907 回答