gpt4 book ai didi

android - 需要 GCM 3.0 刷新注册 token 吗?

转载 作者:IT王子 更新时间:2023-10-28 23:31:14 28 4
gpt4 key购买 nike

使用最新的 GCM 更新 (3.0) 是否仍然需要在重启等情况下处理刷新注册 token ? This article讨论了使 GCM 可靠,并涵盖了注册 token 可以更改的几种情况。在最新版本下这些步骤是必要的吗?在 IO 2015 的谈话中,他们说注册 token 是好的,直到从设备上卸载应用程序。

InstanceID instanceID = InstanceID.getInstance(this);
String token = instanceID.getToken(getString(R.string.gcm_defaultSenderId),
GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);

最佳答案

注册 token 重启后不应该刷新,但在其他情况下可能会刷新,所以你需要处理它。

使用更新后的 API,您需要实现 InstanceIDListenerService 来处理 token 刷新,如 google-services#android#gcm 中的示例。示例应用

    /**
* Called if InstanceID token is updated. This may occur if the security of
* the previous token had been compromised. This call is initiated by the
* InstanceID provider.
*/
// [START refresh_token]
@Override
public void onTokenRefresh() {
// Fetch updated Instance ID token and notify our app's server of any changes (if applicable).
Intent intent = new Intent(this, RegistrationIntentService.class);
startService(intent);
}

关于可能发生 token 刷新的其他情况。

An existing registration token may cease to be valid in a number of scenarios, including:
- If the client app unregisters with GCM.
- If the client app is automatically unregistered, which can happen if the user uninstalls the application. For example, on iOS, if the APNS Feedback Service reported the APNS token as invalid.
- If the registration token expires (for example, Google might decide to refresh registration tokens, or the APNS token has expired for iOS devices).
- If the client app is updated but the new version is not configured to receive messages.

For all these cases, remove this registration token from the app server and stop using it to send messages.

To protect the client app and app server from potential malicious re-use of registration tokens, you should periodically initiate token refresh from the server. When GCM registration token refresh is initiated from server side, the client app must handle a tokenRefreshed message with the GCM registration client/server handshake
See the API reference for more information on identity and token refresh procedure.

关于android - 需要 GCM 3.0 刷新注册 token 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30622683/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com