【问题标题】:Flutter IOS push notification not workingFlutter IOS推送通知不起作用
【发布时间】:2020-07-13 23:00:27
【问题描述】:

在我的 Flutter 应用程序中,推送通知适用于 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,"success":1,"failure":0,"canonical_ids":0,"results":[{"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 图像,显示了已添加的推送通知功能。

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

【问题讨论】:

    标签: iphone flutter firebase-notifications


    【解决方案1】:

    你必须从苹果下载apn密钥,跟随this线程一步一步。

    【讨论】:

    • 我已经取得了一些进展,所以在问题中也添加了这些细节。感谢您的时间和帮助。
    【解决方案2】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2020-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-25
      • 2012-05-08
      • 2023-03-17
      • 1970-01-01
      相关资源
      最近更新 更多