0

I want to add a flutter app into my existing native app, which I am able to do succesfully using flutter docs. After this, I want to log crashes and other data using firebase for the flutter screens. Since normal implementation of Flutter Fire requires changes to be made in the android and iOS folders, but these folders do not exist in flutter project. So any ideas on how to do it?

4

1 回答 1

0

我遇到过同样的问题。

我通过这种方式解决了:

  1. 不要在 ios 和 android 文件夹中进行更改。
  2. 使用回调在本机端发送您的崩溃信息。
  3. 仅在本机应用程序中配置 FarebaseCrashlytics。

例如:

Swift 中的原生端:

let methodChannel = FlutterMethodChannel(name: "FLUTTER_CHANNEL", binaryMessenger: flutterEngine.binaryMessenger)
                methodChannel.setMethodCallHandler { (call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
                    if call.method == "HANDLE_ERROR" {
                        let userInfo: [String: String] = [
                            "deviceId": UIDevice.current.identifierForVendor!.uuidString
                        ]
                        var errorData = "";
                        if let args = call.arguments as? Dictionary<String, Any> {
                            errorData = args["data"] as? String ?? ""
                        }

                        let error = NSError(domain: errorData, code: 0, userInfo: userInfo)

                        Crashlytics.crashlytics().record(error: error)
                    }
                }

颤振侧:

   Future<void> _handleErrorNative([String errorData]) async {
    try {
      final methodChannel = MethodChannel("FLUTTER_CHANNEL");
      await methodChannel.invokeMethod(
        'HANDLE_ERROR',
        {
          "data": errorData,
        },
      );
    } on PlatformException catch (_) {
      print("_handleErrorNative PlatformException");
    }
  }

请记住,崩溃只会在重新打开应用程序后发送。

于 2022-01-21T12:39:25.677 回答