Reputation: 3372
I know I must be doing something wrong with swift... the new API declares a pair of methods...
class func openParentApplication(_ userInfo: [NSObject : AnyObject]!,
reply reply: (([NSObject : AnyObject]!,
NSError!) -> Void)!) -> Bool
Which can be used in the watch kit extension... and
func application(application: UIApplication!, handleWatchKitExtensionRequest userInfo: [NSObject : AnyObject]!, reply: (([NSObject : AnyObject]!) -> Void)!) {
which can be used in the parent application to handle the request....
I know I am doing something wrong, probably with swift, but the reply object is supposed to be where I can send information back to the extension, but I cannot figure out how to set values into the reply object/dictionary in the handlewatchkitextentionrequest method... I know its just me not understanding the swift syntax, but everything I have tried has failed... how do I put a value/define this dictionary? I have tried creating a dictionary and assigning it to reply, nope, tried to access elements of it no dice... I know this must be simple, but I am just not seeing it.
Upvotes: 2
Views: 2104
Reputation: 23078
Watchkit Extension:
// Call the parent application from Apple Watch
// values to pass
let parentValues = [
"value1" : "Test 1",
"value2" : "Test 2"
]
WKInterfaceController.openParentApplication(parentValues, reply: { (replyValues, error) -> Void in
println(replyValues["retVal1"])
println(replyVaiues["retVal2"])
})
iOS App:
// in AppDelegate.swift
func application(application: UIApplication!, handleWatchKitExtensionRequest userInfo: [NSObject : AnyObject]!, reply: (([NSObject : AnyObject]!) -> Void)!) {
// retrieved parameters from Apple Watch
println(userInfo["value1"])
println(userInfo["value2"])
// pass back values to Apple Watch
var retValues = Dictionary<String,String>()
retValues["retVal1"] = "return Test 1"
retValues["retVal2"] = "return Test 2"
reply(retValues)
}
Upvotes: 4
Reputation: 3372
Wow, why was this so hard to find an answer too, apparently this is the proper way inside the
func application(application: UIApplication!, handleWatchKitExtensionRequest userInfo: [NSObject : AnyObject]!, reply: (([NSObject : AnyObject]!) -> Void)!) {
you send it back via:
reply(["x":"y"])
Upvotes: 1