【发布时间】:2020-01-26 07:35:58
【问题描述】:
所以我通过 PHP 发送 fcm
$msg = array
(
'badge' => '1',
'body' => $notificationBody,
'tag' => "185",
'title' => $notificationTitle,
'icon' => 'myicon',
'sound' => 'mySound',
'priority' => 'high',
'show_in_foreground' => True,
'click_action' => 'FLUTTER_NOTIFICATION_CLICK',
);
$fields = array
( 'to' => $toNotification,
'notification' => $msg );
$headers = array
(
'Authorization: key=MyKEEEy',
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
print_r($result);
curl_close($ch);
现在,即使我不打开应用程序,它也可以在 android 上运行。但是当我在我的 ios 模拟器上尝试时,通知仅在我打开应用程序时显示。
我的颤振文件
_fcm.configure(
onMessage: (Map<String, dynamic> message) async {
setState(() {
_counter++;
});
showDialog(
context: context,
builder: (context) => AlertDialog(
content: ListTile(
title: Text(message['notification']['title']),
subtitle: Text(message['notification']['body']),
),
actions: <Widget>[
FlatButton(
child: Text('Ok'),
onPressed: () {
Navigator.of(context).pop();
setState(() {
_counter = _counter - 1;
});
},
),
],
),
);
},
onLaunch: (Map<String, dynamic> message) async {
print("launch");
},
onResume: (Map<String, dynamic> message) async {
print("resume");
},
);
我已经在 firebase 上添加了 apn 密钥
我该如何解决?我错过了什么吗?
【问题讨论】:
-
我对 php 通知了解不多,但我已经通过 node.js 函数解决了这个问题,所以你想把 node 函数放在 google firebase 函数中,那么你应该检查一下github.com/hardik584/Chatbox-Notification
标签: flutter firebase-cloud-messaging