watchkit 应用程序如何与 iOS 中的 iPhone 父应用程序通信


嗨,我想

在手表套件应用程序上实现示例应用程序。 我想显示父应用程序的一些信息,该应用程序在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:]}

请建议如何从扩展应用程序获取手表应用程序中的数据。提前谢谢。

在我的手表应用程序中,我想设置我的地图视图,所以我要求我的应用程序提供一个位置。

- (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))];
        }
    }];
}

然后我从我的应用程序委托中放回位置:

- (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"});
}

最新更新