【问题标题】:Why the FCM not working on ios in flutter为什么 FCM 在 Flutter 中无法在 ios 上工作
【发布时间】:2021-08-10 16:15:03
【问题描述】:

我正在按照这些步骤使用 firebase 消息向我的应用添加推送通知,但在所有这些步骤之后它不起作用

ios_client

APNs

<key>FirebaseAppDelegateProxyEnabled</key>
<false/>

final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
  void firebaseTrigger(BuildContext ctx) async {
    _firebaseMessaging.configure(
      onMessage: (Map<String, dynamic> message) async {
        print("onLaunch: $message");
        Fluttertoast.showToast(
          msg: message['notification']['title'],
          toastLength: Toast.LENGTH_LONG,
          gravity: ToastGravity.TOP,
          timeInSecForIosWeb: 6,
        );
      },
      onLaunch: (Map<String, dynamic> message) async {
        Navigator.push(
          context,
          MaterialPageRoute(
            builder: (context) => NotificationScreen(),
          ),
        );
      },
      onResume: (Map<String, dynamic> message) async {
        Navigator.push(
          context,
          MaterialPageRoute(
            builder: (context) => NotificationScreen(),
          ),
        );
      },
    );
  }

  @override
  void initState() {
    super.initState();
    firebaseTrigger(context);
    _firebaseMessaging.requestNotificationPermissions(
        const IosNotificationSettings(
            sound: true, badge: true, alert: true, provisional: true));
    _firebaseMessaging.onIosSettingsRegistered
        .listen((IosNotificationSettings settings) {
      print("Settings registered: $settings");
    });
  }

但推送通知仅适用于 ios,但适用于 android 任何人都可以帮助我解决我的问题

编辑:我的 appDelegate

【问题讨论】:

  • 你在模拟器上运行吗?
  • 查看我不熟悉 ios 的文档,但也可以查看 firebase.flutter.dev/docs/messaging/apple-integration
  • @GbengaBAyannuga 在真实设备中没有
  • @Assassin 我正在关注这份文件,但同样的问题
  • 让我看看你的有效载荷

标签: flutter dart push-notification firebase-cloud-messaging


【解决方案1】:
override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        let firebaseAuth = Auth.auth()
        firebaseAuth.setAPNSToken(deviceToken, type: AuthAPNSTokenType.unknown)

    }

将此添加到您的 appDelegate.... 这是 appDelegate 的示例

import UIKit
import Flutter

import Firebase
import FirebaseAuth
import UserNotifications
import FirebaseMessaging


@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    

    application.registerForRemoteNotifications()
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
  
   override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        let firebaseAuth = Auth.auth()
        firebaseAuth.setAPNSToken(deviceToken, type: AuthAPNSTokenType.unknown)

    }
    override func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        let firebaseAuth = Auth.auth()
        if (firebaseAuth.canHandleNotification(userInfo)){
            print(userInfo)
            return
        }
    
    }
   
  
 
}

【讨论】:

  • 如果#available(iOS 10.0, *) { UNUserNotificationCenter.current().delegate = self as,我应该删除它吗? UNUserNotificationCenterDelegate } 来自我的 appDelegate 并把你的?
  • 删除它...添加后...更新让我看看你粘贴在哪里
  • 这个答案会不会让ios通知权限出现??
猜你喜欢
  • 2018-12-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-21
  • 2021-09-18
  • 1970-01-01
  • 2021-11-28
  • 2022-08-18
相关资源
最近更新 更多