如何在Android应用程序中从谷歌云消息客户端取消注册



我在xamarin环境中使用GCM(谷歌云消息)和Azure通知中心开发了一个Android应用程序。

问题是:我不知道如何取消订阅以前的标签。即使我再次卸载安装,应用程序也会继续接收我之前订阅的每个标签的通知。

我需要实现以下功能:

protected override void OnUnRegistered(Context context, string registrationId)
{
     throw new NotImplementedException();
}

我认为您需要在Azure通知中心注销。

protected override void OnUnRegistered(Context context, string registrationId)
{
    if (hub != null)
        hub.Unregister();
}

其中hub与您在OnRegistered 中使用的NotificationHub相同

使用GoogleCloudMessagingunregister()方法停止接收GCM消息。

protected override void OnUnRegistered(Context context, string registrationId){
     //Run on background
     GoogleCloudMessaging.getInstance(context).unregister();
}

公共无效注销()

注销应用程序。调用unregister()将停止任何消息从服务器。这是一个阻塞呼叫,您不应该从UI线程。您应该很少(如果有的话)需要调用此方法。它不仅在资源方面很昂贵,而且会失效您的注册ID,不应进行不必要的更改。A.更好的方法是让服务器停止发送消息。仅当您希望应用程序停止使用GCM时才使用unregister永久,或者你有一个令人信服的理由回收你的注册ID。如果我们无法连接到服务器,则抛出IOException注销。

最新更新