2016-10-17 84 views
1

我正在使用REST API,并且正在尝试发送到主题。我知道这个话题存在,因为我可以在通知控制台中看到该主题在那里。而且我可以通过控制台发送测试消息,并且可以正常工作。Firebase云消息传递主题发送,消息不会显示在通知中,也不会发送

但是,当我使用REST api时,我得到一个http状态200的响应,json {“message_id”:8769790390495267408}看起来像一个成功的发送。但是,该消息不会显示在通知中,并且该消息不会发送给订阅的客户端。

我的信息是这样的,这是从文档

https://fcm.googleapis.com/fcm/send 
Content-Type:application/json 
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA 

{ 
    "to": "/topics/foo-bar", 
    "data": { 
    "message": "This is a Firebase Cloud Messaging Topic Message!", 
    } 
} 

,我使用了“服务器密钥”,而不是在Web API密钥。

感谢您的任何帮助。

+0

您是否将此发送给设备? Android或iOS? –

+0

订阅该主题的设备。 iOS版。 – Jay

回答

2

对于iOS,请尝试使用notification而不是data。然后添加priority并将其设置为high。有效负载看起来应该是这样的:

https://fcm.googleapis.com/fcm/send 
Content-Type:application/json 
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA 

{ 
    "to": "/topics/foo-bar", 
    "priority": "high", 
    "notification" : { 
     "body" : "great match!", 
     "title" : "Portugal vs. Denmark", 
     "icon" : "myicon" 
    } 
} 
+0

谢谢。自从最初发布以来,我已转向通知。你是对的,优先事项是需要的。我从文档中看不到这一点。 – Jay

相关问题