我试图使用FCM发送背景通知,但是,我无法使它工作。我可以让推送通知正常工作,但不是背景通知。我看过很多关于这个问题的资料来源,也尝试过很多事情,但是似乎没有什么效果。
我在Capabilities.
问题是这个方法永远不会在后台被调用:
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
}还有很多其他人。
我使用了“优先级”和“content_available”的不同组合: true。包括“通知”,但不包括通知。我说过"content_available":在不同的层次上都是正确的,似乎没有什么起作用的。
我看过:
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) 我真的很挣扎,任何帮助都是非常感谢的!
发布于 2020-12-30 15:43:55
解决办法是把contentAvailable: true
发布于 2021-05-24 20:49:48
尝试在AppDelegate中添加代码:
'Messaging.messaging().delegate = self'
'Messaging.messaging().isAutoInitEnable = true'
'Messaging.messaging().shouldEstablishDirectChannel = true'https://stackoverflow.com/questions/65501590
复制相似问题