应用关闭时未显示Flutter通知

时间:2019-09-26 04:51:57

标签: flutter firebase-cloud-messaging

所以我通过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密钥

我该如何解决?我想念什么吗?

1 个答案:

答案 0 :(得分:0)

iOS模拟器不接收推送通知。您必须在实际设备上运行