获取推送通知的设备令牌的应用程序被删除后, [英] Get device token for push notifications after app was deleted

查看:177
本文介绍了获取推送通知的设备令牌的应用程序被删除后,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您安装的第一次一个应用程序,并希望推送通知注册,应用程序会询问你是否要接收警报与否。这是被永久保存在设置,即使该应用程序的删除后。

When you install an app for the first time and want to register for Push notifications, the app asks you whether you want to receive alerts or not. This is being permanently saved in the settings, even after deletion of the app.

基本上,救我们正在做这个令牌:

Basically, to save the token we are doing this:

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    NSString *token = [[[deviceToken description]
            stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]]
            stringByReplacingOccurrencesOfString:@" " withString:@""];
    [[NSUserDefaults standardUserDefaults] setValue:token forKey:kDeviceTokenKey];
}

但问题是,当应用程序从设备中删除是NSUserDefaults的消灭,但推的设置都没有。这样就不会再问,因此不会再次调用委托方法,因此我没有道理了,但推仍激活。

But the problem is, NSUserDefaults are wiped when the app is removed from the device, but the push settings are not. So it won't ask again, thus don't call the delegate method again, thus I don't have the token anymore, but push is still activated.

有没有机会得到令牌回到描述的场景?

Is there any chance to get the token back in the described scenario?

推荐答案

从<一个href=\"http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/IPhoneOSClientImp.html#//apple_ref/doc/uid/TP40008194-CH103-SW1\">Push通知编程指南

应用程序应该注册每次启动时,给其
  供应商目前的令牌。它调用
  registerForRemoteNotificationTypes:方法来揭开序幕
  注册过程。

An application should register every time it launches and give its provider the current token. It calls the registerForRemoteNotificationTypes: method to kick off the registration process.

通过请求设备令牌,并将其传递给每一个供应商
  计时您的应用程序启动,你帮助确保供应商
  有该设备的当前令牌。如果用户恢复一个备份到
  设备或计算机比备份为创建的一个其它
  (例如,用户将数据迁移到新的设备或计算机),他
  或她必须至少一次启动应用程序,它接收
  再次通知。如果用户备份数据还原到一个新的设备
  或计算机,或重新安装操作系统,设备令牌
  变化。而且,从来没有缓存的设备令牌,并把那个给你
  供应商;总是从系统中获得令牌,只要你需要它。
  如果你的应用程序已经previously注册,呼叫
  registerForRemoteNotificationTypes:结果在操作系统
  立即通过设备令牌委托,而不会产生
  额外的开销。

By requesting the device token and passing it to the provider every time your application launches, you help to ensure that the provider has the current token for the device. If a user restores a backup to a device or computer other than the one that the backup was created for (for example, the user migrates data to a new device or computer), he or she must launch the application at least once for it to receive notifications again. If the user restores backup data to a new device or computer, or reinstalls the operating system, the device token changes. Moreover, never cache a device token and give that to your provider; always get the token from the system whenever you need it. If your application has previously registered, calling registerForRemoteNotificationTypes: results in the operating system passing the device token to the delegate immediately without incurring additional overhead.

要回答你的问题:呼叫 registerForRemoteNotificationTypes:在每次启动,并使用最新的令牌。

To answer your question: Call registerForRemoteNotificationTypes: on every launch, and use the latest token.

这篇关于获取推送通知的设备令牌的应用程序被删除后,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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