Roy*_*hal 7 push-notification node.js firebase flutter firebase-cloud-messaging
我在 nodejs 上使用 firebase-admin 向用户发送推送通知:https ://firebase.google.com/docs/admin/setup
我在颤振上使用 firebase_messaging:https : //pub.dev/packages/firebase_messaging
我正在尝试在 android 和 ios 上发送具有最高优先级的推送通知。
firebase.messaging(firebaseApp).send({
token,
notification,
android: { priority: 'high' },
apns: { headers: { 'apns-priority': '10' }, payload: { aps: { sound: 'default' } } },
data
}
Run Code Online (Sandbox Code Playgroud)
在我的开发设备上,它在应用程序处于后台和终止时都非常有用。
我在 android 和 ios 上都收到推送通知,这些通知在 100% 的时间里明显弹出并发出声音。
问题出在其他设备上 -
如果应用程序在后台,我有时会看到实际的推送通知明显弹出,并发出应有的声音。有时不是。
如果应用程序终止,则会收到推送通知 - 但它既不会明显弹出也不会发出声音,我只能在从屏幕顶部向下滚动菜单时才能看到它,它被列为收到的推送通知。有时根本没有收到通知。
我也尝试将应用程序中通知的优先级更改为实际设备上的高,但没有任何改变。
我的用户一直抱怨他们没有收到推送通知 - 我猜他们要么实际上没有收到它们,要么只是没有看到它们,因为它们是按照我上面描述的静默收到的。
我真的不知道发生了什么以及为什么它不能在我自己的开发设备以外的设备上正常工作。
有任何想法吗?
当我们从 firebase api 发送推送时,有两个标签需要保持完整
如果 android 7.0 或 8.0 以上设备未收到 android_channel_id ,则不会显示通知,因此请始终在 android 清单中设置默认通知通道。我们可以检查我们通过节点设置的 json 请求中的可用标签。 从这里
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="@string/default_notification_channel_id"/>
Run Code Online (Sandbox Code Playgroud)
像这样并确保您在移动端创建通知通道。
String CHANNEL_ID = "your_channel id";
String CHANNEL_DESCRIPTION = "Your description to show in settings";
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, CHANNEL_DESCRIPTION, NotificationManager.IMPORTANCE_HIGH);
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.createNotificationChannel(channel);
Run Code Online (Sandbox Code Playgroud)
如果您看到 flutter 应用程序日志,它会显示一些错误,例如清单中未设置默认频道或通知中未找到频道。
请确保您将日志记录到您的问题中以解决此问题,或与我联系以解决问题。
另请确保您阅读了 此处的 fcm flutter lib中的“可选处理后台消息”部分 ,其中他们提到在 android 文件夹中添加 fcm。
| 归档时间: |
|
| 查看次数: |
3567 次 |
| 最近记录: |