[英]how to Send push notifications from Flutter app
I use firebase messaging to push notifications.我使用 firebase 消息来推送通知。
Now i push notifications from console to users on app, but I want the user to push notifications from app to another user when send message.现在我将通知从控制台推送到应用程序上的用户,但我希望用户在发送消息时将通知从应用程序推送到另一个用户。 How can I do that?
我怎样才能做到这一点?
Knowing that I have saved the device ID of each user on Firestore and the ID is renewed every time the user logs into the application.知道我已经在 Firestore 上保存了每个用户的设备 ID,并且每次用户登录应用程序时都会更新 ID。
I tried using the following code to send notifications in case the user sends a message, but it didn't work我尝试使用以下代码发送通知,以防用户发送消息,但它不起作用
sendNotification(String body, String idToken) async {
await http.post(
(Uri.parse('https://fcm.googleapis.com/fcm/send')),
headers: <String, String>{
'Content-Type': 'application/json',
'Authorization': 'key=$servitoken',
},
body: jsonEncode(
<String, dynamic>{
'notification': <String, dynamic>{
'body': "${body.toString()}",
'title': "!"
},
'priority': 'high',
'data': <String, dynamic>{
'click_action': 'FLUTTER_NOTIFICATION_CLICK',
'id': '1',
'status': 'done'
},
'to': await "${idToken}",
},
),
);
}
,## ,##
I will recommend you to use onesignal instead of just using firebase cloud messaging.我会建议您使用 onesignal 而不是仅使用 firebase 云消息传递。 Onesignal is easy to use and can make your development life more
Onesignal 易于使用,可以让您的开发生活更丰富
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.