【问题标题】:'NSInvalidArgumentException', reason: '+[FIRInstanceIDCheckinPreferences preferencesFromKeychainContents:]: 'unrecognized selector sent to class ''NSInvalidArgumentException',原因:'+[FIRInstanceIDCheckinPreferences preferencesFromKeychainContents:]:'无法识别的选择器发送到类'
【发布时间】:2020-04-12 08:04:16
【问题描述】:

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

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[FIRInstanceIDCheckinPreferences preferencesFromKeychainContents:]: unrecognized selector sent to class 0x10235ca58

我的代码基于 Firebase 的教程,因此我很惊讶它不起作用。代码如下:

import Firebase


    var interpreter: ModelInterpreter?

    func convertTheModel(){


        guard let modelPath = Bundle.main.path( forResource: "model", ofType: "tflite", inDirectory: ""
            )
            else {
                print("not able to load model")
                return

        }

        let localModel = CustomLocalModel(modelPath: modelPath)
        interpreter =  ModelInterpreter.modelInterpreter(localModel: localModel)

        let ioOptions = ModelInputOutputOptions()
        do {
            try ioOptions.setInputFormat(index: 0, type: .float32, dimensions: [1, 22])
            try ioOptions.setOutputFormat(index: 0, type: .float32, dimensions: [1, 1])
        } catch let error as NSError {
            print("Failed to set input or output format with error: \(error.localizedDescription)")
        }



    let inputs = ModelInputs()
    var inputData = Data()

        do {
            for _ in 0 ..< 22 {

              // require fixed-point values or the original bytes.
              var RandomNumber = Float.random(in: 0 ..< 1)

              // Append normalized values to Data object.
              let elementSize = MemoryLayout.size(ofValue: RandomNumber)
              var bytes = [UInt8](repeating: 0, count: elementSize)
              memcpy(&bytes, &RandomNumber, elementSize)
              inputData.append(&bytes, count: elementSize)
          }
          try inputs.addInput(inputData)
        } catch let error {
          print("Failed to add input: \(error)")
        }


        interpreter!.run(inputs: inputs, options: ioOptions) { outputs, error in
            guard error == nil, let outputs = outputs else { return }

            print(outputs)
        }

    }


经过一些调试,我隐约猜测错误是由这行代码引起的: interpreter = ModelInterpreter.modelInterpreter(localModel: localModel)

其他信息

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

/Users/Path/Application_Name/Update/Pods/GoogleMobileVision/Detector/Frameworks/GoogleMobileVision.framework/GoogleMobileVision(VisionExtension.pbobjc_0848a2b53cac8a49ea32ab4e6cb931d4.o)
ld: 46 duplicate symbols for architecture arm64
clang: error: linker command failed with exit code

以下是我所做的总结:

  1. 我清理了 buildingfolder
  2. 重新安装所有 pod:pod deintegratepod install
  3. 将 No Common Blocks 设置为 no
  4. 删除所有 -ObjC,如 this Link 所述。

我的 Podfile 是:

platform :ios, '13.0'

target 'My Project' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  # Pods for My Project
  pod 'Firebase/Database'
  pod 'Firebase/Auth'
  pod 'GoogleMobileVision/FaceDetector'
  pod 'Firebase/Firestore'
  pod 'Firebase/MLModelInterpreter'


end


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

编辑

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

@保罗·伯斯特里安

这是我粘贴-ObjC的位置:

【问题讨论】:

  • 首先你明白unrecognised selector异常是什么意思吗?
  • 首先感谢您的即时回复。我没有详细了解它,但我了解选择器是过去的遗物,来自Objective-C。它根据选择器选择要在对象上执行的函数。 (Information) 这些信息如何帮助解决我的问题?
  • 选择器是方法的另一个名称。异常的意思是您试图在没有该方法的对象上调用该方法。换句话说,您使用了错误的对象。
  • This 可能是问题所在。
  • @trojanfoe 谢谢,我去看看

标签: ios swift xcode firebase compiler-errors


【解决方案1】:

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

【讨论】:

  • 我试过了,但我运行的问题与问题中描述的相同:ld: 46 duplicate symbols for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation)。可能是我在错误的Other Linker Flags 上添加了-ObjC。我粘贴在 Podstarget 文件上:(我的问题中的图片)对吗?
  • 应该是应用的项目设置,而不是 Pods 项目。如果您仍然遇到重复符号问题,请分享详细信息...
  • 我试过了,但我遇到了与问题中描述的相同的问题。你知道如何解决它。既没有遇到构建错误,也没有遇到其他崩溃错误?
  • 我需要查看有关重复符号错误的更多详细信息
猜你喜欢
  • 2015-08-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-28
相关资源
最近更新 更多