简体   繁体   English

iOS强制GCM刷新注册令牌

[英]iOS Force GCM to refresh registration token

I use GCM in my Swift app and would like to ask GCM a new registration token. 我在Swift应用程序中使用了GCM ,并想向GCM索取一个新的注册令牌。

I know that it's done automatically by GCM and I handle it in onTokenRefresh , but I want to know if it's possible to request GCM to refresh the token manually (to have a different one). 我知道它是由GCM自动完成的,我在onTokenRefresh中进行了处理,但是我想知道是否可以请求GCM手动刷新令牌 (以使用另一个令牌 )。

I tried to unregister for remote notification and register back to run the process ( tokenWithAuthorizedEntity etc ...) but the registration token sent is the same. 我试图取消注册以进行远程通知,然后重新注册以运行该过程( tokenWithAuthorizedEntity等),但是发送的注册令牌相同。

any solution to do this ? 有解决方案吗?

Use the deleteTokenWithAuthorizedEntity: method before asking for a new token as derived in the official docs . 在要求获取官方文档中派生的新令牌之前,请使用deleteTokenWithAuthorizedEntity:方法。 Also, if that fails, delete the Instance ID itself, which will delete all tokens associated with that Instance ID, in which case make sure to also call getIDWithHandler: before asking for a new token. 另外,如果失败,请删除实例ID本身,这将删除与该实例ID相关联的所有令牌,在这种情况下,请确保在请求新令牌之前也调用getIDWithHandler:

Anyway, why do you need to refresh this token? 无论如何,为什么需要刷新此令牌? Although you can delete them, this is not their intended use. 尽管可以删除它们,但这不是它们的预期用途。 If you're just looking to ID a particular device uniquely, use the Instance ID itself OR use alternate methods of generating random strings (and then re checking if this random string has actually never been generated and used before). 如果您只是想唯一地标识一个特定的设备,请使用实例ID本身或使用其他方法生成随机字符串(然后重新检查该随机字符串是否实际上从未生成和使用过)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM