【问题标题】:FCM for Flutter IOS notification not show when app is in background or terminatedFlutter IOS 通知的 FCM 在应用程序处于后台或终止时不显示
【发布时间】:2020-07-04 12:44:35
【问题描述】:

我使用 this 为 Flutter 实现了 Firebase 云消息传递。在 Android 中一切正常,但 iOS 推送通知仅在应用程序处于前台时显示。

请帮我在后台显示通知应用程序并终止。

这些是我到目前为止所做的步骤

  1. 创建了 firbase 项目。
  2. 将 GoogleService-Info.plist 添加到 xcode。
  3. 将 firebase_messaging: ^6.0.13 & flutter_local_notifications: ^1.3.0 添加到 pubspec.yaml 中。
  4. Then I enable push notification and background modes

  5. 在颤抖中

    FirebaseMessaging firebaseMessaging = new FirebaseMessaging();
    FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
    new FlutterLocalNotificationsPlugin();
    
    
    
    @override
    void initState() {
    super.initState();
    var android = new 
    AndroidInitializationSettings('mipmap/ic_launcher');
    var ios = new IOSInitializationSettings();
    var platform = new InitializationSettings(android, ios);
    flutterLocalNotificationsPlugin.initialize(platform);
    
    firebaseMessaging.configure(
    onLaunch: (Map<String, dynamic> msg) async{
    print(" onLaunch called ${(msg)}");
    },
    
    onResume: (Map<String, dynamic> msg) async{
    print(" onResume called ${(msg)}");
    },
    onMessage: (Map<String, dynamic> msg) async{
    showNotification(msg);
    print(" onMessage called ${(msg)}");
    },
    );
    firebaseMessaging.requestNotificationPermissions(
    const IosNotificationSettings(sound: true, alert: true, badge: 
    true));
    firebaseMessaging.onIosSettingsRegistered
    .listen((IosNotificationSettings setting) {
    print('IOS Setting Registed');
    });
    firebaseMessaging.getToken().then((token) {
    update(token);
    });
    getCashedInfo();
    }
    
    
    
    showNotification(Map<String, dynamic> msg) async {
    var android = new AndroidNotificationDetails(
    'sdffds dsffds',
    "CHANNLE NAME",
    "channelDescription",
    );
    var iOS = new IOSNotificationDetails();
    var platform = new NotificationDetails(android, iOS);
    await flutterLocalNotificationsPlugin.show(
     0, "This is title", "this is demo", platform);
    }
    
    update(String token) {
    print(token);
    
    }
    
  6. 我在 Xcode 中添加了

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

【问题讨论】:

  • 那么,你找到答案了吗?
  • 喂?你找到答案了吗?我也有同样的问题。
  • 我猜不是。这个问题有几十个线程,没有任何记录的、可重复的更正。
  • 有什么解决办法吗?我被这个困住了......

标签: flutter firebase-cloud-messaging


【解决方案1】:

发布此问题后,iOS 的后台消息处理功能以前不受支持。但是GitHub post 中提到了一些解决方法。

使用通知服务扩展是一种方法,是的。

Flutter 是一个优秀的框架,它允许构建和发布漂亮的 用户界面以奇异的速度。然而,这是否意味着它提供了我们的一切 想要(从我们的角度)?不,这是否意味着我们已经放弃了 Flutter 并使用 SwiftUI(越野车)或故事板?没有。

我们决定在 UI 上使用 Flutter,我们正在处理很多事情 除了推送通知之外的所有业务逻辑 以及其他一些次要功能-这是您更擅长的 滚动你自己的。

实现通知服务扩展并使其与 颤振是几个小时的事情,考虑到有多少失败 考虑到入门级,这有点有趣但并不令人震惊。

我们确实将通知服务扩展与通知内容一起使用 将更高级的通知延长几个月,但最后我们 放下它并移至 PushKit(显然带有 CallKit)并滚动了我们的 自己的通知演示者逻辑导致我们同时放弃 通知服务和内容扩展。

我对那些需要添加推送通知支持的人的建议 Flutter - 在原生端解决它,你以后会感谢自己的。

如何使用 NotificationServiceExtension(本机代码) firebase_messaging?

在同一个 GitHub 帖子上,特别是 2020 年 8 月 4 日在 this thread 中。提到现在支持此功能。

大家好,当前的开发版本现已支持此功能,以及 macOS 平台也支持登陆(请参阅migration guide doc 以获得完整的 更新日志以及如何升级)。

有关试用此开发版本的讨论/反馈,请参阅 #4023 - 希望得到反馈。

【讨论】:

  • 看到is not yet supported 然后下面几行说this feature is now supported. 令人困惑。就像你说的,它支持的,所以第一句话是不正确的,可能会让读者感到困惑。您可能想说“以前以前不支持”之类的话。
  • 感谢提出,我会更新我的答案。
猜你喜欢
  • 2016-11-28
  • 2021-07-02
  • 2017-04-28
  • 2022-01-26
  • 2017-06-25
  • 2019-02-25
  • 2022-12-22
  • 2020-09-01
  • 2021-06-06
相关资源
最近更新 更多