How to use the device token in method other than didRegisterForRemoteNotificationsWithDeviceToken?

后端 未结 2 519
说谎
说谎 2020-12-21 15:11

I got the device token through didRegisterForRemoteNotificationsWithDeviceToken method. I wanted to use the device token in another method. I tried it in this w

2条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-21 15:48

    You can add the device token to the NSUserDefaults dictionary like so:

    -(void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
    {
        [[NSUserDefaults standardUserDefaults] setObject:deviceToken forKey:@"deviceToken"];
    

    This can then be accessed in other methods like so:

    NSString *deviceToken = [[NSUserDefaults standardUserDefaults] objectForKey:@"deviceToken"];
    

提交回复
热议问题