algolia / voice-overlay-ios

🗣 An overlay that gets your user’s voice permission and input as text in a customizable UI
https://alg.li/voice
MIT License
544 stars 62 forks source link

Crash when voice controller finishes #4

Closed IchordeDionysos closed 5 years ago

IchordeDionysos commented 5 years ago

Is this already usable?

Because I get a crash when the controller finishes. https://cl.ly/cf78707938f5/Screenshot%2525202018-10-12%252520at%25252016.19.37.png

voice output: error Error Domain=kAFAssistantErrorDomain Code=4 "(null)" UserInfo={NSUnderlyingError=0x600001698000 {Error Domain=SiriCoreSiriConnectionErrorDomain Code=4 "(null)"}}
voice output: error Error Domain=kAFAssistantErrorDomain Code=4 "(null)" UserInfo={NSUnderlyingError=0x600001698000 {Error Domain=SiriCoreSiriConnectionErrorDomain Code=4 "(null)"}}
Fatal error: Attempted to read an unowned reference but the object was already deallocated2018-10-12 16:32:59.928673+0200 simpleclub[5988:1421136] Fatal error: Attempted to read an unowned reference but the object was already deallocated

Process finished with exit code 0
IchordeDionysos commented 5 years ago

I start it like this:

@objc func startVoiceSearch() {
        let overlay = VoiceOverlayController()
        overlay.start(on: self, textHandler: { text, final in
            print("voice output: \(String(describing: text))")
            print("voice output: is it final? \(String(describing: final))")
            if final {
                self.searchControllerView.searchInput.text = text
            }
        }, errorHandler: { error in
            print("voice output: error \(String(describing: error))")
        })
    }
spinach commented 5 years ago

Hi @IchordeDionysos ,

I actually realised what is the problem. You need to keep a reference to your overlay variable in your ViewController, or else it won't be owned by anyone and you will lose reference to it. This should solve your problem. Just move the let overlay = VoiceOverlayController() below your class declaration (as shown in the usage README)