Flutter IOS FCM推送通知没有出现在通知栏

3
我刚接触Flutter和IOS。我正在为Android和IOS配置FCM推送通知,对于Android它很好用。我参考了这篇文章: https://medium.com/@jun.chenying/flutter-tutorial-part3-push-notification-with-firebase-cloud-messaging-fcm-2fbdd84d3a5e 。对于IOS,如果应用程序已打开并且我同时从Firebase控制台发送FCM,则Flutter on message会被调用(见屏幕截图,日志在那里)。但是,如果我关闭应用程序,则通知不会出现在通知栏中,但我在Android应用程序中收到了通知。我不知道问题出在哪里,是苹果配置文件还是Flutter的问题。

以下是我的Flutter代码:

IOS构建设置和签名与功能

IOS build Settings

    class FirebaseNotifications {
       FirebaseMessaging _firebaseMessaging;
       SharedPreferences _sharedPreferences;

       void setUpFirebase() {
         _firebaseMessaging = FirebaseMessaging();
         initializeSharedPreferences();
         firebaseCloudMessaging_Listeners();
        }

        void initializeSharedPreferences() async {
        _sharedPreferences = await SharedPreferences.getInstance();
        }

        void firebaseCloudMessaging_Listeners() {
        if (Platform.isIOS) iOS_Permission();
        _firebaseMessaging.getToken().then((token) {
        _sharedPreferences.setString(Preferences.device_token, token);
         print('Token'+token);
         });

         _firebaseMessaging.configure(
          onMessage: (Map<String, dynamic> message) async {
          print('on message $message');
         },
          onResume: (Map<String, dynamic> message) async {
          print('on resume $message');
         },
         onLaunch: (Map<String, dynamic> message) async {
         print('on launch $message');
         },
       );
     }

     void iOS_Permission() {
     _firebaseMessaging.requestNotificationPermissions(
     IosNotificationSettings(sound: true, badge: true, alert: true));
     _firebaseMessaging.onIosSettingsRegistered
     .listen((IosNotificationSettings settings) {
     print("Settings registered: $settings");
    });
   }
  }
5个回答

4
若有其他人在未来遇到此问题,进一步解释此答案。问题是在Info.plistFirebaseAppDelegateProxyEnabled被设置为布尔值而非字符串,应改为:
    <key>FirebaseAppDelegateProxyEnabled</key>
    </false>

变成

    <key>FirebaseAppDelegateProxyEnabled</key>
    <string>0</string>

2
你救了我的命!我必须迁移使用 Notifee 的经典通知到静默推送通知,但是无法使其正常工作...直到我使用字符串值禁用了 FirebaseAppDelegateProxyEnabled 。你还必须实现 didRegisterForRemoteNotificationsWithDeviceTokendidReceiveRemoteNotification 来使其正常工作,并且不要忘记在你的 apns 负载中加入 content-available - Hurobaki
太感谢了...我一直在撞墙 :) - Mohamed Saleh

1

在你的info.plist文件中进行以下替换。

<false/>替换为<string>0</string>

之前:

enter image description here

Now :

enter image description here

信息 : 如果您在info.plist中没有此代码,并且您也没有收到通知,请确保添加它。

不要忘记,这是新代码:

<key>FirebaseAppDelegateProxyEnabled</key>
<string>0</string>

希望它有用。

1
在您的Xcode功能选项卡中看到“Push Notifications(Profile)”是很奇怪的。也许可以再次删除并重新添加。您是否在“后台模式”中勾选了“后台获取”和“远程通知”复选框?

enter image description here


1

在这个问题上,你不是孤单的 - 尝试this的解决方案。

此外,请检查应用程序的调试版本和发布版本是否都无法正常工作 - 有可能通知未被应用程序的调试版本解析。


1
鼓励提供外部资源链接,但请添加上下文说明该链接的内容和原因。在引用重要链接时,请引用最相关的部分,以防目标站点无法访问或永久离线。请确保[答案]。 - dboy

1

我成功地通过这个解决方案修复了问题:

  1. 在您的info.plist文件中:

     FirebaseAppDelegateProxyEnabled: false
    
  2. 将以下代码添加到您的AppDelegate中:

    override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    
       Messaging.messaging().apnsToken = deviceToken
       super.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)
     }
    

当您仅仅是复制内容时,请在 参考链接 中引用您的答案。 - iDecode

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接