2014-07-22 3 views
0

원시 알림을 사용하는 Windows Phone 8 앱을 개발하고 있습니다. 이를 위해 샘플 "How to send and receive raw notifications for Windows Phone 8"을 따르고 있습니다. WP8에서 알림을 푸시하면 항상 새 URI가 생성됩니다.

나는 샘플로 정확하게 코딩 : 나는 장치의 코드를 실행 한 후

public MainPage() 
     { 
      /// Holds the push channel that is created or found. 
      HttpNotificationChannel pushChannel; 

      // The name of our push channel. 
      string channelName = "RawSampleChannel"; 

      InitializeComponent(); 

      // Try to find the push channel. 
      pushChannel = HttpNotificationChannel.Find(channelName); 

      // If the channel was not found, then create a new connection to the push service. 
      if (pushChannel == null) 
      { 
       pushChannel = new HttpNotificationChannel(channelName); 

       // Register for all the events before attempting to open the channel. 
       pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated); 
       pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred); 
       pushChannel.HttpNotificationReceived += new EventHandler<HttpNotificationEventArgs>(PushChannel_HttpNotificationReceived); 

       pushChannel.Open(); 

      } 
      else 
      { 
       // The channel was already open, so just register for all the events. 
       pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated); 
       pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred); 
       pushChannel.HttpNotificationReceived += new EventHandler<HttpNotificationEventArgs>(PushChannel_HttpNotificationReceived); 

       // Display the URI for testing purposes. Normally, the URI would be passed back to your web service at this point. 
       System.Diagnostics.Debug.WriteLine(pushChannel.ChannelUri.ToString()); 
       MessageBox.Show(String.Format("Channel Uri is {0}", 
        pushChannel.ChannelUri.ToString())); 

      } 
     } 

, 나는 앱이 다른 URI 내가 그것을 실행할 때마다 생성되는 것을 보았다.

나는 HttpNotificationChannel.Find (channelName)이 항상 null을 반환한다는 것을 깨달았습니다. (그 이유는 앱이 항상 새로운 URI를 생성하기 때문입니다.)

나는 이미 this을 읽었지만 여전히 도움이되지 못했습니다.

는 그래서, 내 질문은 :

  • 해서는 안 HttpNotificationChannel.Find (CHANNELNAME) 반환 응용 프로그램이 이미 채널을 생성 한 경우 '널'다른 뭔가?

내가 도움이 될만한 것을 놓친 경우 말해주십시오.

답변

0

나는 귀하의 게시물과 언급 된 링크를 통과했습니다. 그것은 channelUri updation 꽤 무작위 것 같습니다 (일반적으로 확실히 응용 프로그램 제거/설치,하지만 다른 시나리오뿐만 아니라 아마도 변경됩니다). 사용자가 올바르게 타겟팅되도록하는 확실한 방법은 channelUri를 다른 고유 식별자와 연결하는 것입니다. 예를 들어, channelUri을 잡은 후 uri와 고유 한 사용자 ID로 서버 데이터베이스를 업데이트하려고 할 수 있습니다. 하위 호출의 경우 동일한 사용자에 대해 채널 만 업데이트 할 수 있습니다. 희망이 조금 도움이됩니다.

관련 문제