![](/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.