0

我正在服務器上實施通知服務,以將通知推送到Android和Iphone。使用Amazon SNS在Android GCM中僅接收默認消息

我現在遇到的問題是我測試的Android設備只接收默認消息。

我的代碼如下: -

主程序

string smsMessageString = "{\"default\": \"This is the default message which must be present when publishing a message to a topic. The default message will only be " + 
                " used if a message is not present for one of the notification platforms.\"," + 
            "\"APNS\": {\"aps\": {\"alert\": \"Check out these awesome deals!\",\"url\": \"www.amazon.com\"}}," + 
            "\"GCM\": {\"data\": {\"message\": \"Check out these awesome deals!\",\"url\": \"www.amazon.com\"}}," + 
            "\"ADM\": {\"data\": {\"message\": \"Check out these awesome deals!\",\"url\": \"www.amazon.com\"}}}"; 


     var smsMessage = new SmsMessageObj 
     { 
      smsMessageSubject = "Test Message", 
      smsMessageBody = smsMessageString 
     }; 

     snsClient.SendPush(endpointArn, smsMessage); 

和SendPush如下: -

public void SendPush(string endpointArn, SmsMessageObj msg) 
    { 
     if (string.IsNullOrEmpty(endpointArn)) 
      throw new Exception("Endpoint ARN was null"); 

     var pushMsg = new PublishRequest 
     { 
      Message = msg.smsMessageBody, 
      MessageStructure = "json", 
      Subject = msg.smsMessageSubject, 
      TargetArn = endpointArn 
     }; 


     _client.Publish(pushMsg); 

    } 

我需要包括什麼更使我能獲得「正確」的Android通知?

我需要app.config中的任何東西嗎?

感謝您的幫助和時間

回答

0

我已經解決了這個問題。我所需要做的就是將Json串聯起來。也許它會在未來幫助別人。所以我做的是: -

 var apns_Json = "{\"aps\": {\"alert\": \"Check out these awesome deals_Apple!\",\"url\": \"www.amazon.com\"}}"; 
     var gcm_Json = "{\"data\": {\"message\": \"Check out these awesome deals_Google!\",\"url\": \"www.amazon.com\"}}"; 
     var adm_Json = "{\"data\": {\"message\": \"Check out these awesome deals!\",\"url\": \"www.amazon.com\"}}"; 

     string smsMessageString = "{\"default\": \"This is the default message which must be present when publishing a message to a topic. The default message will only be " + 
             " used if a message is not present for one of the notification platforms.\"," + 
         "\"APNS\": " + JsonConvert.ToString(apns_Json) + "," + 
         "\"GCM\": " + JsonConvert.ToString(gcm_Json) + "," + 
         "\"ADM\": " + JsonConvert.ToString(adm_Json) + "}";