2016-03-23 6 views
2

IOSプラットフォームに紺碧を使用してブロードキャスト通知を送信する形式を次のようにJSONペイロードを送信します。は、IOSとAndroid

{"aps":{"alert":"Notification Hub test notification"}} 

Androidのペイロード形式であるのに対し:

{"data":{"message":"Notification Hub test notification"}} 

マイSendBroadcastNotification

public void SendBroadcastNotification(string message) { 

    NotificationHubClient hub = NotificationHubClient 
      .CreateClientFromConnectionString(Constants.NotificationsHubConnectionString, "QiKStayNotificationHub",true); 
    var notify = "{ \"data\" : {\"message\":\"" + message + "\"}}"; 
    var appnotify = "{ \"aps\" : {\"alert\":\"" + message + "\"}}"; 
    var task = hub.SendGcmNativeNotificationAsync(notify); 
    task.Wait(); 
} 

ここから私は特にSendGcmNativeNotificationAsyncにアンドロイドに通知を送りますすべてのデバイスにブロードキャストします。あなたは維持する必要があり、通知ハブユーザーのプラットフォームとデバイスを登録同様に

hubClient.SendAppleNativeNotificationAsync(); 
hubClient.SendGcmNativeNotificationAsync(notify); 
+0

SendGcmNativeNotificationAsyncはすべてのアンドロイドデバイスとSendAppleNativeNotificationAにブロードキャストします同期はすべてのリンゴデバイスにブロードキャストされます – Mahesh

答えて

0

ながら

は、だから私は、ペイロードJSON形式を変更するものと

switch (platform.ToLower()) 
      { 
       case "apns": 
        notificationMessage = "{ \"aps\" : {\"alert\":\"" + message + "\"}}"; 
        break; 
       case "gcm": 
        notificationMessage = "{ \"data\" : {\"message\":\"" + message + "\",\"display\":\"" + title + "\"}}"; 
        break; 
       default: 
        break; 
      } 

たりすることができますユーザテンプレートメッセージ

private static async void SendTemplateNotificationAsync() 
{ 
    // Define the notification hub. 
    NotificationHubClient hub = 
     NotificationHubClient.CreateClientFromConnectionString(
      "<connection string with full access>", "<hub name>"); 

    // Sending the notification as a template notification. All template registrations that contain 
    // "messageParam" or "News_<local selected>" and the proper tags will receive the notifications. 
    // This includes APNS, GCM, WNS, and MPNS template registrations. 
    Dictionary<string, string> templateParams = new Dictionary<string, string>(); 

    // Create an array of breaking news categories. 
    var categories = new string[] { "World", "Politics", "Business", "Technology", "Science", "Sports"}; 
    var locales = new string[] { "English", "French", "Mandarin" }; 

    foreach (var category in categories) 
    { 
     templateParams["messageParam"] = "Breaking " + category + " News!"; 

     // Sending localized News for each tag too... 
     foreach(var locale in locales) 
     { 
      string key = "News_" + locale; 

      // Your real localized news content would go here. 
      templateParams[key] = "Breaking " + category + " News in " + locale + "!"; 
     } 

     await hub.SendTemplateNotificationAsync(templateParams, category); 
    } 
} 
+0

こんにちはMahesh、私は通知をブロードキャストしたいので、なぜpnsタグをチェックする必要がありますjsonのペイロード私は同様に "{\"データ\ "" {{"message": "メッセージ": "$(メッセージ)"} 、 'icon': '$(icon)'、{$(params)}}} "; – Priyanka

+0

こんにちはPriyanka、私の更新された答えを確認してください。 – Mahesh

+0

こんにちはありがとう!私はほとんど(新しい {u.Name }を選択db.UsersにUから)同じアプローチを VARのユーザー=適用します。 foreach(ユーザーのvarユーザー) { var notify = "{\"メッセージ\ ":メッセージ+" \ "ユーザーID \":\ "" + user.Name + "\"}} "; var alert = "{\"警告\ ":\" "メッセージ+" \ "}}"; var task = hub.SendGcmNativeNotificationAsync(notify); – Priyanka

関連する問題