Skip to content

Instantly share code, notes, and snippets.

@jiverson
Created February 28, 2015 06:40
Show Gist options
  • Save jiverson/9f25c98724d1df168d50 to your computer and use it in GitHub Desktop.
Save jiverson/9f25c98724d1df168d50 to your computer and use it in GitHub Desktop.
Phone to Watch communication
// Phone
func application(application: UIApplication, handleWatchKitExtensionRequest userInfo: [NSObject : AnyObject]?, reply: (([NSObject : AnyObject]!) -> Void)!) {
if let request = userInfo!["request"] as? String {
if request == "refreshData" {
reply(["fromPhone": NSKeyedArchiver.archivedDataWithRootObject("iPhone data")])
return
}
}
reply([:])
}
// Watch
@IBAction func getLocationBtn() {
WKInterfaceController.openParentApplication(["request": "refreshLoc"],
reply: { (replyInfo, error) -> Void in
if let a = replyInfo["locData"] as? NSData,
b = NSKeyedUnarchiver.unarchiveObjectWithData(a) as? String {
self.locationLbl.setText(b)
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment