Created
February 28, 2015 06:40
-
-
Save jiverson/9f25c98724d1df168d50 to your computer and use it in GitHub Desktop.
Phone to Watch communication
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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