2013-04-17 5 views
1

내 .Net 서버에서 알림을 보내려고합니다. 모든 Android 장치로 Android 애플리케이션을 다운로드했습니다. PushSharp 라이브러리를 사용하고 있습니다. 알림을 보내는 것이 좋습니다. 하지만 사용자가 애플리케이션을 제거하고 agian을 다운로드하면 정식 등록 ID를 알려주는 GCM의 응답을 받으려고합니다. 같은 Android 기기에 견인 알림을 보내는 문제가 있습니다. 하나는 새 ID를 사용하고 다른 하나는 등록되지 않은 ID를 사용하여 데이터베이스에서 해당 ID를 제거하려고합니다. 그래서 하나의 장치에 대해 하나의 알림 만 보낼 수 있습니다. GCM에 의해 트리거 된이 4 가지 이벤트를 등록합니다. 어떤 이벤트에서 내 논리를 수행 할 수 있습니까?PushSharp를 사용하여 GCM 응답을받을 수있는 이벤트 Android 기기로 알림을 보내시겠습니까?

도움이 감사드립니다.

여기 내 코드입니다 :

private static void Events_OnNotificationSent(Notification notification) 
    { 

    } 

    private static void Events_OnNotificationSendFailure(Notification notification, Exception notificationFailureException) 
    { 

    } 



    private static void Events_OnChannelException(Exception exception, PlatformType platformType, Notification notification) 
    { 
    } 



    private static void Events_OnDeviceSubscriptionExpired(PlatformType platform, string deviceInfo, Notification notification) 
    { 

    } 



    private static void Events_OnDeviceSubscriptionIdChanged(PlatformType platform, string oldDeviceInfo, string newDeviceInfo, Notification notification) 
    { 

    } 

답변

0

난 당신이 사용자가 응용 프로그램을 제거 할 경우 데이터베이스에서 장치를 제거 할 제대로 이해합니다. 내 프로젝트에 대해 다음과 같은 논리를 사용하고 있습니다.

private void Events_OnNotificationFailed(object sender, INotification notification, Exception error) 
{ 
    var gcmNotification = notification as GcmNotification; 
    bool userHasUninstalled = error.Message.Contains("Device Subscription has Expired"); 
    bool isAndroidNotification = gcmNotification != null; 
    if (isAndroidNotification && userHasUninstalled) 
    { 
     foreach (var registrationId in gcmNotification.RegistrationIds) 
     { 
      DeleteDeviceByIdentifier(registrationId); 
     } 
    } 
} 
+0

Thnak for you 응답. 나는이 이벤트에서 일하고있다 : private static void Events_OnDeviceSubscriptionExpired (PlatformType 플랫폼, string deviceInfo, 알림 통지) { } – user123456

+0

@Mohammadjouhari : 그럼,'Events_OnDeviceSubscriptionExpired'에서 정규 등록 ID는 어디에서 얻을 수 있습니까? –

+0

@marceln 당신은 어떻게 그것을 얻을 수 있습니까? – user123456