2014-02-18 3 views
1

노드 js 스크립트에 의한 푸른 알림 허브를 사용하여 푸시 알림을 보냅니다. 푸시 알림을 보내고받을 수 있습니다. 데이터를 검색하는 방법을 모르겠습니다. 다음과 같이 푸시를 보냅니다. -푸시 알림에서 데이터를 가져 오는 방법은 무엇입니까?

function sendNotifications(pushMessage) { 
    console.log('inside sendNotifications'); 
    var hub = azure.createNotificationHubService('hubname','connection string'); 

    hub.mpns.sendToast(
     null, 
     { 
      text1: pushMessage, 
      text2: 'some data' 
     }, 
     function (error) 
     { 
      if (!error) 
      { 
       //message send successfully 
       console.log("mpns.sendToast push success: "+error); 
       RESPONSE.send(statusCodes.OK, { ResponseMessage : 'mpns.sendToast message success' }); 
      } 
      else 
      { 
       // msg failed to send 
       console.log("errro error.shouldDeleteChannel: "+error); 
       RESPONSE.send(statusCodes.OK, { ResponseMessage :'mpns.sendToast message error '+error }); 
      } 
     }); 
} 

수신하는 응용 프로그램에 text1과 text2를 수신하고 싶습니다. 어떻게하는지 알려주시겠습니까? 또는 일부 데이터를 푸시하려면 푸시 알림을 다르게 보내야합니까? 푸시 질화와 함께 데이터를 푸시하는 방법은 무엇입니까? 얼마나 큰 데이터를 밀어 넣을 수 있습니까? 앱이 토스트 통지가 수신 될 때 이미 열려 있으면

답변

1

, 통지의 매개 변수를 얻을 수있는 다음과 같은 이벤트 핸들러 (예를 들어 e.Collection[wp:Text1]는 토스트의 제목을 반환합니다) :

void PushChannel_ShellToastNotificationReceived(object sender, NotificationEventArgs e) 
{ 
    StringBuilder message = new StringBuilder(); 
    string relativeUri = string.Empty; 

    message.AppendFormat("Received Toast {0}:\n", DateTime.Now.ToShortTimeString()); 

    // Parse out the information that was part of the message. 
    foreach (string key in e.Collection.Keys) 
    { 
     message.AppendFormat("{0}: {1}\n", key, e.Collection[key]); 

     if (string.Compare(
      key, 
      "wp:Param", 
      System.Globalization.CultureInfo.InvariantCulture, 
      System.Globalization.CompareOptions.IgnoreCase) == 0) 
     { 
      relativeUri = e.Collection[key]; 
     } 
    } 

    // Display a dialog of all the fields in the toast. 
    Dispatcher.BeginInvoke(() => MessageBox.Show(message.ToString())); 

} 

을 경우 토스트 알림을 클릭하여 앱을 연 경우 앱을 연 페이지에서 다음 메소드를 구현할 수 있습니다. 축배 알림의 wp:Param 매개 변수의 쿼리 문자열에 전달 된 매개 변수에 액세스 할 수 있습니다. 이 방법으로 Text1과 Text2를 얻는 방법을 모르겠습니다.

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) 
{ 
    base.OnNavigatedTo(e); 

    // If we navigated to this page 
    // from the MainPage, the DefaultTitle parameter will be "FromMain". If we navigated here 
    // when the secondary Tile was tapped, the parameter will be "FromTile". 
    textBlockFrom.Text = "Navigated here from " + this.NavigationContext.QueryString["NavigatedFrom"]; 

} 

코드 샘플은 here에서 촬영되었다.

+0

앱이 열리지 않는 경우는 어떻게 되나요? 어떻게 처리할까요? @이란 – SD7

관련 문제