'NSInvalidArgumentException',原因:'+[FIRInstanceIDCheckinPreferencespreferencesFromKeychainContents:]:'无法识别的选择器发送到类'

Bru*_*ann 5 xcode compiler-errors ios firebase swift

当我尝试使用 Firebase 中的 MLModelInterpreter 在 Xcode 项目中加载 tflite 文件时,在 Launchsreen 完全可见后出现以下错误:

\n\n
*** Terminating app due to uncaught exception \'NSInvalidArgumentException\', reason: \'+[FIRInstanceIDCheckinPreferences preferencesFromKeychainContents:]: unrecognized selector sent to class 0x10235ca58\n
Run Code Online (Sandbox Code Playgroud)\n\n

我的代码基于 Firebase 的教程,因此令我惊讶的是它不起作用。这是代码:

\n\n
import Firebase\n\n\n    var interpreter: ModelInterpreter?\n\n    func convertTheModel(){\n\n\n        guard let modelPath = Bundle.main.path( forResource: "model", ofType: "tflite", inDirectory: ""\n            )\n            else {\n                print("not able to load model")\n                return\n\n        }\n\n        let localModel = CustomLocalModel(modelPath: modelPath)\n        interpreter =  ModelInterpreter.modelInterpreter(localModel: localModel)\n\n        let ioOptions = ModelInputOutputOptions()\n        do {\n            try ioOptions.setInputFormat(index: 0, type: .float32, dimensions: [1, 22])\n            try ioOptions.setOutputFormat(index: 0, type: .float32, dimensions: [1, 1])\n        } catch let error as NSError {\n            print("Failed to set input or output format with error: \\(error.localizedDescription)")\n        }\n\n\n\n    let inputs = ModelInputs()\n    var inputData = Data()\n\n        do {\n            for _ in 0 ..< 22 {\n\n              // require fixed-point values or the original bytes.\n              var RandomNumber = Float.random(in: 0 ..< 1)\n\n              // Append normalized values to Data object.\n              let elementSize = MemoryLayout.size(ofValue: RandomNumber)\n              var bytes = [UInt8](repeating: 0, count: elementSize)\n              memcpy(&bytes, &RandomNumber, elementSize)\n              inputData.append(&bytes, count: elementSize)\n          }\n          try inputs.addInput(inputData)\n        } catch let error {\n          print("Failed to add input: \\(error)")\n        }\n\n\n        interpreter!.run(inputs: inputs, options: ioOptions) { outputs, error in\n            guard error == nil, let outputs = outputs else { return }\n\n            print(outputs)\n        }\n\n    }\n\n\n
Run Code Online (Sandbox Code Playgroud)\n\n

经过一番调试后,我模糊地猜测该错误是由这行代码引起的:\ninterpreter = ModelInterpreter.modelInterpreter(localModel: localModel)

\n\n

附加信息

\n\n

在出现上述问题之前,我遇到了另一个问题:构建项目时,编译器显示此错误:

\n\n
/Users/Path/Application_Name/Update/Pods/GoogleMobileVision/Detector/Frameworks/GoogleMobileVision.framework/GoogleMobileVision(VisionExtension.pbobjc_0848a2b53cac8a49ea32ab4e6cb931d4.o)\nld: 46 duplicate symbols for architecture arm64\nclang: error: linker command failed with exit code\n
Run Code Online (Sandbox Code Playgroud)\n\n

以下是我所做的总结:

\n\n
    \n
  1. 我清理了建筑文件夹
  2. \n
  3. 重新安装所有 pod: pod deintegrate然后pod install
  4. \n
  5. 将“无公共块”设置为“否”
  6. \n
  7. 按照此链接中所述删除所有 -ObjC 。
  8. \n
\n\n

我的 Podfile 是:

\n\n
platform :ios, \'13.0\'\n\ntarget \'My Project\' do\n  # Comment the next line if you don\'t want to use dynamic frameworks\n  use_frameworks!\n\n  # Pods for My Project\n  pod \'Firebase/Database\'\n  pod \'Firebase/Auth\'\n  pod \'GoogleMobileVision/FaceDetector\'\n  pod \'Firebase/Firestore\'\n  pod \'Firebase/MLModelInterpreter\'\n\n\nend\n\n\n
Run Code Online (Sandbox Code Playgroud)\n\n

如果有人可以提供帮助,我将不胜感激

\n\n

编辑

\n\n

如果有人有其他解决方案来将 tflite 文件(或 h5 文件:查看我之前的问题)加载到 Xcode 项目中,这也会有所帮助

\n\n

@保罗·博斯特里安

\n\n

这是我粘贴的位置-ObjC:\n在此输入图像描述

\n

Pau*_*ien 3

-ObjC 必须位于应用程序中,Other Linker FlagsFirebase 才能正常工作。有关此问题的更多详细信息,请参阅https://github.com/firebase/firebase-ios-sdk/issues/4776 。