问题描述
我正在开发 Flutter 应用(使用 Firebase Firestore 和 FCM),旨在向用户已登录的所有设备发送通知。当用户退出设备时,令牌将从 Firebase 中删除。我正在寻找一种在用户卸载应用程序时删除令牌的解决方案,并且在某种程度上能够为单个用户存储/更新多个设备令牌,而无需基于 Android id 存储令牌。
final FirebaseMessaging firebaseMessaging = FirebaseMessaging();
Future<Map<String,dynamic>> sendAndRetrieveMessage(context) async {
await firebaseMessaging.requestNotificationPermissions(
const IosNotificationSettings(sound: true,badge: true,alert: true,provisional: false),);
await http.post(
'https://fcm.googleapis.com/fcm/send',headers: <String,String>{
'Content-Type': 'application/json','Authorization': 'key=$server_token',},body: jsonEncode(
<String,dynamic>{
'notification': <String,dynamic>{
'body': '${widget.content}','title': '${widget.title}','priority': 'high','data': <String,dynamic>{
'click_action': 'FlutteR_NOTIFICATION_CLICK','status': 'done','body': '${widget.content}','registration_ids': user_tokens,),).then((http.Response response){
final int statusCode = response.statusCode;
print("RESPONSE BODY: " + response.body);
print("STATUS CODE: " + statusCode.toString());
if (statusCode < 200 || statusCode > 400 || response.body == null) {
throw new Exception("Error while fetching data");
}
});
final Completer<Map<String,dynamic>> completer =
Completer<Map<String,dynamic>>();
firebaseMessaging.configure(
onMessage: (Map<String,dynamic> message) async {
completer.complete(message);
},onLaunch: (Map<String,onResume: (Map<String,);
return completer.future;
}
- 在 Firebase 中更新登录令牌,但仅更新一个字符串也意味着仅发送到用户的最新登录设备而忽略其他设备
- 为用户订阅 user_id 主题,但每个发送通知的主题限制为 5 个。我的应用程序需要发送到特定用户列表(由一个共同的主题决定,但一组多个条件),我想避免使用循环,因为通知功能需要为所有接收用户同时工作
- 读取 HTTP 响应消息以检测失败的令牌,响应返回“NotRegistered”但未返回特定的失败令牌
我想知道这在 Flutter 中是否可行,以及是否有针对此问题的解决方案/更简单的方法。谢谢
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)