更新时间:2022-06-10 22:15:35
这个问题我已经有一个星期了.但这已解决.请按照以下步骤操作:
I had had this problem for a week. But it was resolved. Follow these:
application:didRegisterForRemoteNotificationsWithDeviceToken:
中添加 [FIRMessaging消息传递] .APNSToken = deviceToken;
.请记住,当您在服务器中发送消息时,即使您收到一条消息(该消息不包含通知),响应也没有说任何有关推送通知到iOS设备的信息.而且我也不知道如何检查通知是否已发送.[FIRMessaging messaging].APNSToken = deviceToken;
in function application:didRegisterForRemoteNotificationsWithDeviceToken:
. Keep in mind that the response when you send a message in your server did not say anything about the push notification to your iOS devices even you received a message (it did not contain a notification). And I also don't know how to check whether notification delivered or not.我的python服务器代码:
My python server code:
def push_notification():
title = "Your title"
message = "Your message"
ntf_data = {"key": "value"}
fcm_token = "your_fcm_token"
topic = "your_topic"
# apns
alert = ApsAlert(title = title, body = message)
aps = messaging.Aps(alert = alert, sound = "default")
payload = messaging.APNSPayload(aps)
# message
msg = messaging.Message(
notification = messaging.Notification(
title = title,
body = message
),
data = ntf_data,
token = fcm_token,
topic = topic,
apns = messaging.APNSConfig(payload = payload)
)
# send
res = messaging.send(msg)
以及前端反应本地通知侦听器代码:
And frontend react-native notification listener code:
onNotificationListener = firebase.notifications().onNotification((notification) => {
console.log("received notification:", notification)
}
随时询问我的答案是否有任何问题,或者您需要更多信息.编码愉快.
Feel free to ask if there is any problem in my answer or if you need more information. Happy coding.