2016-05-12 5 views
0

現在、Azure Push Notification Serviceを使用してアンドロイド電話にメッセージを送信しています。 This linkによれば、Dozeモードのアプリを扱うためのGCMメッセージの優先度を設定できます。ここでAzure Notification HubでGCM優先度を設定する方法

は、私は現在、それを使用する方法である:ここ

 string content = JsonConvert.SerializeObject(new GCMCarrier(data)); 
    result = await Gethub().SendGcmNativeNotificationAsync(content, toTag); 

はGCMCarrier

public class GCMCarrier 
{ 
    public GCMCarrier(Object _data) 
    { 
     data = _data; 
    } 
} 

は今、私はメッセージに優先順位を追加するにはどうすればよいのですか? GCMを送信するコンストラクタにはデータパラメータしかありませんか?

または私は単にデータと一緒に私の `GCMCarrier」オブジェクトに追加することができ

答えて

2

誰かが使用する方法に試してみて - ?ペイロードに優先度]フィールドを追加することがGitHubのリポジトリas the issueで最近議論されました。 Windows PhoneにはSDKの機能がありますが、Androidのようには見えませんが、AFAIKの通知ハブはパススルーメカニズムなので、ペイロードはGCM自体で処理されます。

0

モデルを作成し、必要なプロパティを正しい形式で追加し、jsonペイロードに変換します。

public class GcmNotification 
{ 
    [JsonProperty("time_to_live")] 
    public int TimeToLiveInSeconds { get; set; } 
    public string Priority { get; set; } 
    public NotificationMessage Data { get; set; } 
} 


public class NotificationMessage 
{ 
    public NotificationDto Message { get; set; } 
} 

public class NotificationDto 
{ 
     public string Key { get; set; } 
     public string Value { get; set; } 
} 

これで、jsonコンバーターでデータを変換できますが、JsonConverterでは小文字の設定を使用することを忘れないでください。私はLowercaseJsonSerializerクラスでこれを実装しています。

private void SendNotification(GcmNotification gcmNotification,string tag) 
    { 
       var payload = LowercaseJsonSerializer.SerializeObject(gcmNotification); 
       var notificationOutcome = _hubClient.SendGcmNativeNotificationAsync(payload, tag).Result; 
} 

public class LowercaseJsonSerializer 
    { 
     private static readonly JsonSerializerSettings Settings = new JsonSerializerSettings 
     { 
      ContractResolver = new LowercaseContractResolver() 
     }; 

     public static string SerializeObject(object o) 
     { 
      return JsonConvert.SerializeObject(o,Settings); 
     } 

     public class LowercaseContractResolver : DefaultContractResolver 
     { 
      protected override string ResolvePropertyName(string propertyName) 
      { 
       return propertyName.ToLower(); 
      } 
     } 
    } 
関連する問題