iosswiftwatchkitwatchos-2dictation

How to start and stop dictation in Apple Watch witout pressing button


I wrote code to use dictation on my apple watch. I used presentTextInputControllerWithSuggestions without suggestions to directly start dictation.

But, I have two problem :

There is my code :

func dictation(){
        self.presentTextInputControllerWithSuggestions([], allowedInputMode: WKTextInputMode.Plain, completion:{
            (results) -> Void in
                 //myCode
            })
    }
override func willActivate(){
   super.willActivate()
   dictation()
}

Do you have solutions ?


Solution

  • Thanks for your help @Feldur

    I tried with delay and it seems to work

    There is my code :

    override init(){
        super.init()
        print("start init")
        let seconds = 1.0
        let delay = seconds * Double(NSEC_PER_SEC)  // nanoseconds per seconds
        let dispatchTime = dispatch_time(DISPATCH_TIME_NOW, Int64(delay))
        dispatch_after(dispatchTime, dispatch_get_main_queue(), {
            self.dictation()
        })
        print("end init")
    }
    

    There are my logs :

    start init
    end init
    start awakeWithContext
    end awakeWithContext
    start willactivate
    end willactivate
    start didAppear
    end didAppear
    start dictation
    

    My screen appears and after, my dictation starts.

    Do you have an idea for stop dictation when user stops speaking ?