Skip to content

Instantly share code, notes, and snippets.

@litoarias
Last active June 19, 2018 08:49
Show Gist options
  • Save litoarias/0e6438e97213174bb456addce7c59bf8 to your computer and use it in GitHub Desktop.
Save litoarias/0e6438e97213174bb456addce7c59bf8 to your computer and use it in GitHub Desktop.
Watch Tutorial 8
class ViewController: UIViewController {
// 1: Get singleton class whitch manage WCSession
var connectivityHandler = SessionHandler.shared
// 2: Counter for manage number of messages sended
var messagesCounter = 0
// ...
/// Send messages on main thread
@IBAction func sendMessage(_ sender: UIButton) {
messagesCounter += 1
// 3: Send message to apple watch, we don't wait to response, only trace errors
connectivityHandler.session.sendMessage(["msg" : "Message \(messagesCounter)"], replyHandler: nil) { (error) in
print("Error sending message: \(error)")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment