我想在手表套件应用程序上实现示例应用程序。我想显示一些在iphone中运行的父应用程序的信息,现在我想通过按钮点击手表套件从预制件动作获取手表套件应用程序中的数据。我已经使用委托方法与扩展应用程序进行后台通信,但是当我在
中打印错误时,我得到相同的错误[InterfaceController openParentApplication:dict reply:^(NSDictionary *replyInfo, NSError *error)
{
NSLog(@"%@",[replyInfo objectForKey:@"Key"]);
NSLog(@"error:-%@",[error description]);
}
获取错误....
Error: Error Domain=com.apple.watchkit.errors Code=2 "The UIApplicationDelegate in the iPhone App never called reply() in -[UIApplicationDelegate application:handleWatchKitExtensionRequest:reply:]" UserInfo=0x7f8603227730 {NSLocalizedDescription=The UIApplicationDelegate in the iPhone App never called reply() in -[UIApplicationDelegate application:handleWatchKitExtensionRequest:reply:]}
请建议我如何从extention app获取watch app中的数据。 在此先感谢。
答案 0 :(得分:2)
在我的观看应用中,我想设置我的mapview,所以我向我的应用询问了一个位置。
- (void)awakeWithContext:(id)context {
[super awakeWithContext:context];
// Configure interface objects here.
[WKInterfaceController openParentApplication:@{} reply:^(NSDictionary *replyInfo, NSError *error) {
if (replyInfo) {
[self.map setRegion:MKCoordinateRegionMake(CLLocationCoordinate2DMake([replyInfo[@"lat"] doubleValue], [replyInfo[@"lon"] doubleValue]), MKCoordinateSpanMake(0.05, 0.05))];
}
}];
}
然后我从我的app delegate中放回位置:
- (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void (^)(NSDictionary *))reply
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.google.com"]];
reply(@{@"lat": @"22.3175899",@"lon": @"114.2212058"});
}