[英]Flutter, Firebase ios, cloud message doesn't show when app in background, only if app in foreground
I'm using flutter dependancies:我正在使用 flutter 依赖项:
firebase_messaging: ^7.0.3
flutter_local_notifications: ^3.0.1+6
I send firebase cloud message like this:我这样发送 firebase 云消息:
{
"to": "/topics/demo_ios"
"notification" : {
"body" : "Hi there now now",
"title" : "Wow!",
"sound": "default"
},
"priority": "high"
"data": {
"title": "Hi there yes",
"body": "Wow",
}
}
In ios the notification shows when the app is in the foreground, however when in the background it doesn't show at all.在 ios 中,当应用程序处于前台时,通知会显示,但在后台时则根本不显示。 I tried reading and fixing many things, but is still doesn't work.
我尝试阅读和修复很多东西,但仍然无法正常工作。 I set background fetch, remote notificaitons, and background processing from xcode, and it still doesn't work.
我从 xcode 设置了后台获取、远程通知和后台处理,但它仍然不起作用。
I set FirebaseAppDelegateProxyEnabled to false in the plist file, but it didn't help.我在 plist 文件中将 FirebaseAppDelegateProxyEnabled 设置为 false,但没有帮助。
I request permission:我请求许可:
_messaging.requestNotificationPermissions(
const IosNotificationSettings(sound: true, badge: true, alert: true, provisional: false)
);
_messaging.onIosSettingsRegistered.listen((event) {print('2124: ios Setting registered');});
first I recommend you to update the plugin to firebase_messaging: ^8.0.0-dev.8
, because iOS background handling is enabled there.首先,我建议您将插件更新为
firebase_messaging: ^8.0.0-dev.8
,因为在那里启用了 iOS 后台处理。 See here this change: 在这里看到这个变化:
Next, how to integrate all of that to your flutter project, please follow official documentation FlutterFire (this is documentation just after 8.xx-dev versions of the plugin.接下来,如何将所有这些集成到您的 flutter 项目中,请遵循官方文档FlutterFire (这是插件的 8.xx-dev 版本之后的文档。
Finally, please read more about APN, because Apple is handling differently those messages and you need to have the APNSConfig
property inside your script for sending notifications.最后,请阅读有关 APN 的更多信息,因为 Apple 处理这些消息的方式不同,您需要在脚本中包含
APNSConfig
属性以发送通知。
If you are sending notifications via FirebaseAdmin, then please read this .如果您通过 FirebaseAdmin 发送通知,请阅读此内容。
Do not forget, that in that case, you need to set content_available=True
which is contained inside the APNSConfig
property, so basically if you are using FirebaseAdmin you should include also property similar to this one:不要忘记,在这种情况下,您需要设置
content_available=True
,它包含在APNSConfig
属性中,所以基本上如果您使用 FirebaseAdmin,您还应该包括类似于以下的属性:
apns=messaging.APNSConfig(
payload=messaging.APNSPayload(
aps=messaging.Aps(
alert='alert text',
sound='s',
content_available=True,
mutable_content=True,
category='c',
thread_id='t',
custom_data={
'id': 'xxx',
'type': 'xxx',
'title': 'Robb',
'content': 'Axxxx',
'image': 'xxx',
'deepLink': 'xxxx',
},
),
)
),
I was also having the same problem,try to upload IPA file on testflight then it work hope so.我也遇到了同样的问题,尝试在testflight上上传IPA文件然后希望如此。
Well, the solution was quite simple, and a mistake on my behalf.好吧,解决方案很简单,代表我犯了一个错误。
As the documnents pub.dev state:作为文档 pub.dev state:
Generate the certificates required by Apple for receiving push notifications following this guide in the Firebase docs.按照 Firebase 文档中的本指南生成 Apple 接收推送通知所需的证书。 You can skip the section titled "Create the Provisioning Profile".
您可以跳过标题为“创建配置文件”的部分。
Here is the link: https://firebase.google.com/docs/cloud-messaging/ios/certs这是链接: https://firebase.google.com/docs/cloud-messaging/ios/certs
I forgot to do these steps.我忘了做这些步骤。 After doing this, it worked
这样做之后,它起作用了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.