简体   繁体   English

Flutter,Firebase ios,当应用程序在后台时,云消息不显示,仅当应用程序在前台时

[英]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: 在这里看到这个变化:

  • iOS background handler support. iOS 后台处理程序支持。

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.

相关问题 Flutter Firebase 如何控制通知在应用程序处于前台时不显示 - Flutter Firebase how to control notification not to show when the app is in foreground firebase_messaging 回调在前台时不会触发。 iOS 应用程序 Flutter - firebase_messaging callbacks don't fire when in foreground . iOS app Flutter Flutter Firebase Cloud Messaging 未在 Ios 上显示徽章编号 - Flutter Firebase Cloud Messaging doesn't show badge number on Ios Firebase 消息在应用程序在后台和前台运行时有效。 但是,当应用程序终止时没有通知 - Firebase message works when app in background and foreground. However when app terminated no notifications Flutter Firebase 云消息 - 应用程序在后台时的通知 - Flutter Firebase Cloud Messaging - Notification when app in background 当应用程序处于前台时(颤动)在 iOS 中接收 fcm - Receiving fcm in iOS when app is foreground (flutter) 当应用程序在后台并在前台接收时,为什么在 IOS 上收不到 FCM 通知? Flutter - Why does not receive FCM notifications on IOS when the app is in background and receive in foreground? Flutter 当应用程序处于后台或终止时,Flutter IOS 通知的 FCM 不显示 - FCM for Flutter IOS notification not show when app is in background or terminated 前台应用程序抖动时未收到 Firebase 推送通知? - Firebase Push Notification not received when flutter app in foreground? 应用程序处于前台时未收到推送通知 ios flutter - Push Notification not received when app is in foreground ios flutter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM