【问题标题】:How to check if user disabled notifications in FCM?如何检查用户是否在 FCM 中禁用了通知?
【发布时间】:2020-12-28 15:29:36
【问题描述】:

我在我的 Dart/Flutter 应用中使用 Firebase 云消息传递。下面的代码使用检索到的 android 通知令牌更新用户文档。

FirebaseMessaging().getToken().then((token) {
  _usersRef.doc(user.id).update({
    "notificationAndroidToken": token,
  });
});

然后我在我的云函数中阅读了notificationAndroidToken。效果很好,除非我错误地认为如果用户关闭了他们的通知(例如,为空或为空),令牌将无效。确定是否在云功能中为我的应用启用通知的最佳方法是什么?我在我的搜索中发现了一些匹配结果,但很多都已过时或适用于不同的开发环境。

【问题讨论】:

标签: flutter dart firebase-cloud-messaging


【解决方案1】:

firebase_messaging 包不提供任何方法来检查是否通过在平台上调用NotificationManagerCompat.areNotificationsEnabled 启用通知。 awesome_notifications 包提供了这样一个isNotificationAllowed 方法。

【讨论】:

  • 完美。我本来打算看看 awesome_notifications,因为它的通知很漂亮。会试一试
  • @buttonsrtoys 有用吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多