Mcrich
Mcrich

Reputation: 125

-[FBLPromise HTTPBody]: unrecognized selector sent to instance 0x600001afa700 error on non-initial launch. Google Translate MLKit

I am trying to add Google MLKit Translate into my SwiftUI Project. I am already using firebase via SPM and only after the initial launch get this error: -[FBLPromise HTTPBody]: unrecognized selector sent to instance 0x600001afa700

Here is my code:

App Delegate

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        ...
        FirebaseApp.configure()
        ...
        let spanishRemoteTranslator = TranslateRemoteModel.translateRemoteModel(language: .spanish)
        if ModelManager.modelManager().isModelDownloaded(spanishRemoteTranslator) {
            print("Spanish Translator Downloaded")
        }else {
            print("Downloading Spanish Translator")
            
            ModelManager.modelManager().download(spanishRemoteTranslator, conditions: ModelDownloadConditions(allowsCellularAccess: true, allowsBackgroundDownloading: true))
        }
        return true
}

Then I call it like so:

if ModelManager.modelManager().isModelDownloaded(spanishModel) {
    Translator.translator(options: englishSpanishTranslator).translate(buis.name!) { translatedText, error in
        if error == nil {
            if let translatedText = translatedText {
                name = translatedText
            }else {
                print("error = \(error)")
            }
        }else {
            print("error = \(error)")
        }
    }
}else {
    print("error = Spanish not downloaded")
}

I have also tried using the built in FirebaseMLKitDownload and that doesn't have translator. What is going on?

Upvotes: 5

Views: 4556

Answers (1)

jrk
jrk

Reputation: 106

Probably an author of this post found solution of this problem (judging by the comment) but I decided to write this post because few hours ago during taking my first steps with Firebase I had the same error. I hope my post may be helpful for each other.

I had no idea how to find solution but after few hours of debugging I noticed that the problem occurs when I had initialized project with Firebase using dependency manager built-in in the Xcode and then I tried to initialize Firestore using CocoaPods. To be more specific, first thing I do was Firebase installation using this one:

Xcode package dependencies manager

Then, I started using CocoaPods like:

$ pod init
$ vim Podfile // adding 'firebase/firestore' dependency or specific line from https://github.com/firebase/firebase-ios-sdk
$ pod install
$ open <ProjectName>.xcworkspace

In the next step, I tried to check basic Firestore operations like creating collection and documents with data and when I run the app - I got similar error. It was an exception during app run.

I think in my case the problematic thing was possible duplicates because of supplying the project with a Firebase (with all dependencies) twice.

So, I removed dependency installed from the Xcode manager. In my Info.plist there is no dependencies:

Xcode project Info.plist

Then, from the terminal I removed Pods directory and just called an update.

$ rm -rf Pods
$ pod update

All dependencies were re-installed and workspace has been recreated. Now, after these steps everything works fine.

Upvotes: 4

Related Questions