在哪里可以存储 iOS 设备令牌以备后用? [英] Where can I store the iOS device token for later use?

查看:29
本文介绍了在哪里可以存储 iOS 设备令牌以备后用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我通过 didRegisterForRemoteNotificationsWithDeviceToken 获取设备令牌.但是,我需要在用户登录后稍后在我的应用程序中使用设备令牌.

Right now I'm getting the device token via didRegisterForRemoteNotificationsWithDeviceToken. However, I need to use the device token later on in my application after my user logs in.

我以后如何从应用程序的其他地方访问 deviceToken,如果不能,我如何/在哪里可以将它存储在 didRegisterForRemoteNotificationsWithDeviceToken 中以便我以后可以检索它?

How can I access the deviceToken from elsewhere in application later on, and if I cannot, how/where can I store it in didRegisterForRemoteNotificationsWithDeviceToken so I can retrieve it later on?

推荐答案

最简单的方法是使用NSUserDefaults

保存:

NSUserDefaults * ud = [NSUserDefaults standardUserDefaults];
[ud setObject:myPushToken forKey:@"currentPushToken"];
[ud synchronize];

恢复:

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

这篇关于在哪里可以存储 iOS 设备令牌以备后用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆