![](/img/trans.png)
[英]Flutter Firebase how to control notification not to show when the app is in foreground
[英]Flutter, Firebase ios, cloud message doesn't show when app in background, only if app in foreground
我正在使用 flutter 依赖项:
firebase_messaging: ^7.0.3
flutter_local_notifications: ^3.0.1+6
我这样发送 firebase 云消息:
{
"to": "/topics/demo_ios"
"notification" : {
"body" : "Hi there now now",
"title" : "Wow!",
"sound": "default"
},
"priority": "high"
"data": {
"title": "Hi there yes",
"body": "Wow",
}
}
在 ios 中,当应用程序处于前台时,通知会显示,但在后台时则根本不显示。 我尝试阅读和修复很多东西,但仍然无法正常工作。 我从 xcode 设置了后台获取、远程通知和后台处理,但它仍然不起作用。
我在 plist 文件中将 FirebaseAppDelegateProxyEnabled 设置为 false,但没有帮助。
我请求许可:
_messaging.requestNotificationPermissions(
const IosNotificationSettings(sound: true, badge: true, alert: true, provisional: false)
);
_messaging.onIosSettingsRegistered.listen((event) {print('2124: ios Setting registered');});
首先,我建议您将插件更新为firebase_messaging: ^8.0.0-dev.8
,因为在那里启用了 iOS 后台处理。 在这里看到这个变化:
接下来,如何将所有这些集成到您的 flutter 项目中,请遵循官方文档FlutterFire (这是插件的 8.xx-dev 版本之后的文档。
最后,请阅读有关 APN 的更多信息,因为 Apple 处理这些消息的方式不同,您需要在脚本中包含APNSConfig
属性以发送通知。
如果您通过 FirebaseAdmin 发送通知,请阅读此内容。
不要忘记,在这种情况下,您需要设置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',
},
),
)
),
我也遇到了同样的问题,尝试在testflight上上传IPA文件然后希望如此。
好吧,解决方案很简单,代表我犯了一个错误。
作为文档 pub.dev state:
按照 Firebase 文档中的本指南生成 Apple 接收推送通知所需的证书。 您可以跳过标题为“创建配置文件”的部分。
这是链接: https://firebase.google.com/docs/cloud-messaging/ios/certs
我忘了做这些步骤。 这样做之后,它起作用了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.