2016-03-23 15 views
2

IOS platformunu kullanarak Yayın bildirim gönder aşağıdaki biçimde JSON yükü gönderir: Android yük biçimidirIOS için gök mavisi ve android

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

oysa:

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

Benim 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(); 
} 

Buradan itibaren özellikle SendWcmNativeNotificationAsync'e bildiriyorum. Tüm cihazlar için yayın ant. Eğer sürdürmesi gerektiğini bildirim göbeğine kullanıcının platformu ile cihazı kaydederken aynı şekilde

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

SendGcmNativeNotificationAsync, tüm android cihazlara ve SendAppleNativeNotificationA'ya yayın yapacak Senkronizasyon tüm apple cihazlarına yayınlayacaktır – Mahesh

cevap

0

iken

yüzden yük JSON biçimini değiştirmek zorundadır

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

veya olabildiğince kullanıcı şablonu mesajı

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

Merhaba Mahesh, bildirimi yayınlamak istiyorum, pes etiketini neden kontrol etmeliyim? Json yükünün daha fazla etiket koyabildiği başka bir yol var mı? Aynı şekilde "{\" data \ ": {\" mesaj \ ": \" "+ mesaj +" \ "}}" veya değişken dynmicjson gönderebileceğim dinamik parametrelerim var = "{'data': {'message': '$ (message)' 'simgesi': '$ (ikon)', {$ (parametreler)}}} "; – Priyanka

+0

Merhaba Priyanka, lütfen güncellenmiş yanıtımı kontrol edin. – Mahesh

+0

Merhaba Teşekkürler! Neredeyse (yeni { u.Name } seçmek db.Users içinde u) aynı yaklaşımı var users = uygulanan; foreach (kullanıcılarda var olan kullanıcı) varsayı = "{\" data \ ": {\" message \ " user.Name + "\"}} "; var alert = "{\" aps \ ": {\" alert \ ": \" "+ message +" \ "}}"; var task = hub.SendGcmNativeNotificationAsync (bildir); – Priyanka

İlgili konular