2015-01-11 105 views
1

如何從特定標籤中取消註冊一個設備。 我用tag發送通知,它運行良好。但即使我註銷仍然是通知。使用GCM進行Azure推送通知

protected async void HandleRegistration(Context context, Intent intent) 
     { 


      string registrationId = intent.GetStringExtra("registration_id"); 
      string error = intent.GetStringExtra("error"); 
      string unregistration = intent.GetStringExtra("unregistered"); 


//Retriving string From The Memory 

      ISharedPreferences preferences = PreferenceManager.GetDefaultSharedPreferences(context); 
      string groupname = preferences.GetString ("GroupName",""); 


      var nMgr = (NotificationManager)GetSystemService (NotificationService); 

      if (!String.IsNullOrEmpty (registrationId)) { 
       NativeRegistration = await Hub.RegisterNativeAsync (registrationId,new[] {groupname.ToString()}); 

       var notificationNativeRegistration = new Notification (Resource.Drawable.notification, "Your Device Successfully Registered To "+groupname.ToString()); 
       var pendingIntentNativeRegistration = PendingIntent.GetActivity (this, 0, new Intent (this, typeof(MainActivity)), 0); 

       notificationNativeRegistration.SetLatestEventInfo (this, "Device ID ", NativeRegistration.RegistrationId, pendingIntentNativeRegistration); 
       nMgr.Notify (_messageId, notificationNativeRegistration); 
       _messageId++; 
      } 
      else if (!String.IsNullOrEmpty (error)) { 
       var notification = new Notification (Resource.Drawable.notification, "Gcm Registration Failed."); 
       var pendingIntent = PendingIntent.GetActivity (this, 0, new Intent (this, typeof(MainActivity)), 0); 
       notification.SetLatestEventInfo (this, "Gcm Registration Failed", error, pendingIntent); 
       nMgr.Notify (_messageId, notification); 
       _messageId++; 
      } 
      else if (!String.IsNullOrEmpty (unregistration)) { 
       if (NativeRegistration != null) 
        await Hub.UnregisterAsync (NativeRegistration); 

       var notification = new Notification (Resource.Drawable.notification, "Unregistered successfully."); 
       var pendingIntent = PendingIntent.GetActivity (this, 0, new Intent (this, typeof(MainActivity)), 0); 
       notification.SetLatestEventInfo (this, "MyIntentService", "Unregistered successfully.", pendingIntent); 
       nMgr.Notify (_messageId, notification); 
       _messageId++; 
      } 
     } 

我想知道如何註銷以前標記爲的設備?

回答

1

您必須在Microsoft Visual Studio中使用服務總線瀏覽器(Download)才能查看所有註冊的設備。您也可以從註冊設備列表中取消註冊設備。

+0

<15:30:19>異常:遠程服務器返回錯誤:(401)未經授權。此操作需要管理索賠。 TrackingId:bf65054d-036a-467e-b3e2-1a8d34ed8ff7_G7,時間戳:1/11/2015 10:00:19 AM –

+0

非常感謝jahanzaib aslam但我需要通過編碼本身取消註冊。因爲它必須是動態的權利? –

+0

我不認爲你可以在編碼中做到這一點。這是Azure中的一個問題 –