1

I try to send the identifier vendor from IOS app to WatchKit extension when the App is Launched or the view has been loaded using watch connectivity and sendMessage method. It works perfectly when I called in event of button ( when clicked on button). But It doesn't work when I called this method in ViewDidLoad. Seem likes It didn't call the sendMessage and I always get empty String from the id Dictionary

override func viewDidLoad() {
    super.viewDidLoad()
    //Construct wCsession to handle connection between Watch and App

    if (WCSession.isSupported()) {
        self.session = WCSession.default()
        self.session.delegate = self
        self.session.activate()

        let id = ["id" : uuid]
        print(id)
        self.session.sendMessage(id, replyHandler: nil, errorHandler: nil)
        print("DEVICE ID SENT")

    }


}
Van
  • 127
  • 1
  • 1
  • 8
  • 1
    Where is uuid defined? Does it have value by the time you send it? Have you tried adding a replyHandler and errorHandler to print out the sendMessage result? – xiangxin Jul 25 '17 at 06:50
  • uuid is generated by identifer vendor method. I try many approaches including moving the declaration WCsession into AppDelegate in both sides (ios app and watch app). But It seems like sometimes It worked and sometimes It return the error when I run the code again, a bit weird. I found this post similar to my problem but dont know why https://stackoverflow.com/questions/31282834/wcsession-sendmessage-works-50-50 – Van Jul 25 '17 at 07:53
  • @Van Please include your declaration of uuid in the question. – Dávid Pásztor Jul 25 '17 at 13:24

0 Answers0