I have developed and deployed our Apple Watch Extension App using the simulator. It's been approved and is available right now on the app store, so Apple are happy!
Today I was able to get my hands on a physical watch and have discovered a real problem - I can only interact watch-phone, if the app on my phone is not just open, but also active...thus defeating the object.
I am implementing the below method in the appDelegate
of the phone app as a proxy to get my live data and return it to the watch.
I basically pass in a request to the appDelegate
- I check the userInfo for which data should be returned, then the phone app does the business and returns a userInfo dictionary containing data for the watch to parse:
-(void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void (^)(NSDictionary *))reply {
if ([userInfo objectForKey:@"GetWatchData"]) {
[TPWatchData configureWatchData:^(BOOL success) {
if (success) {
reply([TPWatchData watchData]);
} else {
reply(@{@"FAIL":@"AppDelegate"});
}
}];
}
}
I am calling it in the watch using this approach on the watch extension
(just one example of the calls I make):
[TPWPlanList openParentApplication:@{@"GetWatchData":@1} reply:^(NSDictionary *replyInfo, NSError *error) {
if ([replyInfo objectForKey:@"Overview"]) {
if (error.code == 0) {
if ([replyInfo objectForKey:@"FAIL"]) {
// Something failed
} else {
self.dic_overview = [replyInfo objectForKey:@"Overview"];
//[self reloadPlanListTable];
}
} else {
// Something failed
}
}
}];
As already stated, this worked perfectly in the simulator and actually works perfectly on the physical watch - but ONLY if I have the main app open on the phone and active. The minute the app is in the background or the phone display sleeps, no data is passed using the above method.
Any thoughts? I am clearly doing something wrong, but I've managed to get to the point of the entire thing being live and on real devices, before it's bitten me.
Many thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…