2017-05-03 36 views
1

我正在向ios發送通知。沒有圖像的通知功能完美,但不能與圖像一起使用。當我搜索解決方案時,他們都會像設置'mutable-content'=> true一樣說。是的,但是如何?我可能非常愚蠢,不能理解這實際上意味着什麼。我把params爲這個..使用php的firebase web api的IOS圖像通知

$arr = ['type' => 'msg', 'data' => '', 'text' => 'Hello', 'image_url' => '']; 
$fields = array(
      'to' => '/topics/iostest', 
      'notification' => $arr, 
      'mutable-content'=> 1, 
      'priority' => 'high' 
     ); 

僅適用於iOS閱讀「通知」,並收到這樣..

'aps': { 
    alert : 'Hello' 
} 

不接受「可變內容」 ... 的人誰上工作我希望ios和php都能解決這個問題。請幫忙。謝謝。

回答

0

檢字可變內容在你的JSON。請設置mutable_content而不是可變內容。 APNS自動轉換它。下面JSON格式

使用豐富的推送通知 注:在JSON content_available領域是可選的,mutable_content是必需的。

{ 
    "to": "dWB537Nz1GA:APA91bHIjJ5....", 
    "content_available": true, 
    "mutable_content": true, 
    "data": 
    { 
     "message": "Offer!", 
     "mediaUrl": "https://upload.wikimedia.org/wikipedia/commons/thumb/2/2a/FloorGoban.JPG/1024px-FloorGoban.JPG" 
    }, 
    "notification": 
    { 
     "body": "Enter your message", 
     "sound": "default" 
    } 
} 

,你應該得到這樣的

{

aps =  { 

    alert = "Enter your message"; 

    "content-available" = 1; 

    "mutable-content" = 1; 

    sound = default; 

}; 

"gcm.message_id" = "0:1498075182894674%4e5015e84e5015e8"; 

mediaUrl = "https://upload.wikimedia.org/wikipedia/commons/thumb/2/2a/FloorGoban.JPG/1024px-FloorGoban.JPG"; 

message = "Offer!"; 

}

0

使用從火力您的JSON fromat推送通知這個JSON格式應該是

{ "registration_ids" : [Send Array of Device Token], "data" : { 
"image_url" : "send your image here" 
    "message" : "Send your message here" },"notification" : { 
"title" : "APP Name", 
"sound" : "default", 
"priority" : "high" }} 
+0

感謝您的回答的有效載荷,但我的代碼也可以正常使用,用於發送推沒有圖像的通知。我的問題是我無法發送圖像通知。 –

+0

你有沒有嘗試以上格式的圖像發送推送? 在推送通知有限制,你可以發送大量的數據 –