【发布时间】:2021-04-06 15:21:57
【问题描述】:
我正在尝试使用 FCM 发送后台通知,但是我无法让它工作。我可以让推送通知正常工作,而不是后台通知。我查看了有关此主题的大量资源并尝试了很多方法,但是似乎没有任何效果。
- 我在 XCode > Capabilities 中启用了“推送通知”。
- 我在 XCode > 功能的后台模式中选中了“远程通知”
- 我已正确注册设备令牌并正确配置 APN(推送通知有效)
问题是这个方法永远不会在后台被调用:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void)
我尝试过的一些 JSON 格式是
{
"notification": {
"title": "title",
"body": "body",
},
"data":{
"name":"name",
},
"content_available": true,
"apns":{
"headers":{
"apns-priority": "5",
"apns-push-type": "background"
},
},
topic: topic,
}
{
"data":{
"title":'title",
"body":"body",
},
"notification":{
"title":"mytitle",
"body":"mybody",
"content_available": true
},
topic: topic
}
还有很多其他的。
我使用了“priority”和“content_available”的不同组合:true。包括“通知”而不包括它们。我已将 "content_available": true 放在不同的级别上,但似乎没有任何效果。
我看过:
FCM background notifications not working in iOS https://izziswift.com/fcm-background-notifications-not-working-in-ios/
Firebase FCM silent push notifications for iOS
https://firebase.google.com/docs/cloud-messaging/ios/receive
还有许多其他堆栈溢出帖子。
使用我尝试过的一些 JSON 配置,我得到了这个错误,我不确定为什么:
Error: Process exited with code 16
at process.on.code (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/invoker.js:275:22)
at process.emit (events.js:198:13)
at process.EventEmitter.emit (domain.js:448:20)
at process.exit (internal/process/per_thread.js:168:15)
at Object.sendCrashResponse (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/logger.js:37:9)
at process.on.err (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/invoker.js:271:22)
at process.emit (events.js:198:13)
at process.EventEmitter.emit (domain.js:448:20)
at emitPromiseRejectionWarnings (internal/process/promises.js:140:18)
at process._tickCallback (internal/process/next_tick.js:69:34)
我真的很挣扎,任何帮助将不胜感激!
【问题讨论】:
-
你有没有让这个工作?我遇到了类似的问题
标签: ios firebase notifications firebase-cloud-messaging