是否可以使用swift从客户端找到推送通知?我在网上搜索了一下,发现的唯一例子和文档都与Firebase Cloud Functions
和/或使用Firebase Console
严格相关。
我想知道是否可以使用客户端的Firebase Cloud Messaging
创建并发送通知。
实际上可以使用firebase rest api,可以使用以下端点发送通知:
https://fcm.googleapis.com/fcm/send
HTTP请求必须是具有以下标头的POST请求:
授权:密钥=<server_key>
内容类型:application/json
和以下正文:
{
"to" : "<FCM TOKEN>",
"collapse_key" : "type_a",
"priority": 10,
"data" : {
"body" : "Notification",
"title": "Notification title"
}
}
当然,你需要知道应该接收通知的目标设备的FCM令牌,或者至少知道设备/用户订阅的主题。如果你想向特定主题发送通知,请使用以下主体:
{
"to" : "/topics/<YOUR_TOPIC>",
"collapse_key" : "type_a",
"priority": 10,
"data" : {
"body" : "Notification",
"title": "Notification title"
}
}