gpt4 book ai didi

flutter - 当应用程序处于后台或终止时,Flutter IOS 通知的 FCM 不显示

转载 作者:行者123 更新时间:2023-12-04 13:56:55 30 4
gpt4 key购买 nike

我使用 this 为 Flutter 实现了 Firebase 云消息传递.所有事情在 Android 中都运行良好,但 iOS 推送通知仅在应用程序处于前台时显示。

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

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

  • 创建了 firbase 项目。
  • 将 GoogleService-Info.plist 添加到 xcode。
  • 将 firebase_messaging: ^6.0.13 & flutter_local_notifications: ^1.3.0 添加到 pubspec.yaml 中。
  • Then I enable push notification and background modes
  • flutter 腾
    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);

    }
  • 在Xcode中我添加了
    if #available(iOS 10.0, *) {
    UNUserNotificationCenter.current().delegate = self as?
    UNUserNotificationCenterDelegate
    }
  • 最佳答案

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

  • https://github.com/FirebaseExtended/flutterfire/issues/47#issuecomment-594614522

  • Using Notification Service Extension is one way to do it, yes.

    Flutter is excellent framework that allows to build and ship beautifulUI in bizarre speed. However does this mean it provides everything wewant (from our perspective)? No. Does this mean we have drop Flutterand use SwiftUI (buggy) or storyboards? No.

    We made decision to use Flutter for UI and we are handling pretty muchall business logic there except when it comes to push notificationsand some other minor features as well - this is what you are better ofrolling your own.

    Implementing Notification Service Extension and making it work withFlutter is matter of a few hours and considering how many fail to doso is somewhat amusing but not shocking considering the entry level.

    We did use Notification Service Extension with Notification ContentExtension for fancier notifications for some months but at the end wedropped it and moved to PushKit (w/ CallKit obviously) and rolled ourown notification presenter logic which resulted us dropping bothNotification Service and Content Extension.

    My advice for those who need to add push notifications support forFlutter - solve it on native side, you will thank yourself later.


  • https://github.com/FirebaseExtended/flutterfire/issues/47#issuecomment-595657844

  • How about using the NotificationServiceExtension (native code) withfirebase_messaging?


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

    Hey all, this is now supported in the current dev release, along withmacOS platform support landing as well (See the migration guidedoc for a fullchangelog and how to upgrade).

    For discussions/feedback around trying out this dev release please see#4023 - would love feedback.

    关于flutter - 当应用程序处于后台或终止时,Flutter IOS 通知的 FCM 不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60823974/

    30 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com