Flutter IOS推送通知不起作用

时间:2020-04-02 03:13:09

标签: iphone flutter firebase-notifications

在我的Flutter应用程序中,PUSH通知适用于 Android ,但对于 IOS ,我会收到通知警报,但可以打印通过onMessage方法在控制台中进行通知。

以下是我的命令和输出。

curl -X POST --header "Authorization: key=<API_KEY>" \
--Header "Content-Type: application/json" \
https://fcm.googleapis.com/fcm/send \
-d "{\"to\":\"<DEVICE_TOKEN>\",\"notification\":{\"body\":\"Testing\"},\"priority\":10}"

IOS的​​输出是:

{“ multicast_id”:9037043763539529381,“成功”:1,“失败”:0,“ canonical_ids”:0,“结果”:[{“ message_id”:“ 0:158620223403259%62c34b3562c38b95”}]}}

以下是收到通知时执行的代码块。

 _firebaseMessaging.configure(
  onBackgroundMessage: null,
  onMessage: (Map<String, dynamic> message) async {
    // app int he foreground
    print('This works on IOS and Android both');
  },
  onResume: (Map<String, dynamic> message) async {
    // App is in the background
     print('This works on IOS and Android both');
    // But no notification alert shown to the user to click (android everything works fine)

  },
  onLaunch: (Map<String, dynamic> message) async {
    // app terminated
    print('This works on IOS and Android both');
    // But no notification alert shown to the user to click But no notification alert shown to the user to click (android everything works fine)
  },
);

以下是我的Xcode图像,其中显示了添加的“推送通知”功能。 enter image description here

任何帮助将不胜感激...

2 个答案:

答案 0 :(得分:0)

您必须从Apple下载apn密钥,并逐步遵循this线程。

答案 1 :(得分:0)

我在didFinishLaunchingWithOptions方法内的“ AppDelegate.swift”中添加了这一行,它解决了我的问题:

如果#available(iOS 10.0,*){UNUserNotificationCenter.current()。delegate = self as? UNUserNotificationCenterDelegate}

//我在插件的文档中找到了这个,希望它可以解决您的问题!