【问题标题】:How watchkit app communicate with iphone parent application in ioswatchkit 应用程序如何与 ios 中的 iphone 父应用程序通信
【发布时间】:2015-03-16 05:32:18
【问题描述】:

您好,我想在手表套件应用程序上实现示例应用程序。我想显示在 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:]}

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

【问题讨论】:

  • 转到Appdelegate.m并实现应用程序:handleWatchKitExtensionRequest:reply: method
  • 是的,我在应用程序中实现了代码:handleWatchKitExtensionRequest:reply 方法在 appdelegate 方法中,但我仍然遇到同样的错误,并且在调试条件下到达此处理程序方法
  • 你有没有通过回复块来观看应用程序?
  • 请问是什么意思。以及我们如何在回复块中写请建议
  • 是的,我在回复块中传递数据信息并返回字典

标签: ios watchkit xcode-6.2


【解决方案1】:

在我的手表应用中,我想设置我的地图视图,所以我向我的应用询问位置。

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

【讨论】:

  • 在我的应用程序中,我正在执行此类型- (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void(^)(NSDictionary *replyInfo))reply { [self GetWordsFromApplication:userInfo andreply:reply]; }
  • 我怀疑没有调用回复块。
  • 所以请你提供更多关于回复块的建议
  • 你的 GetWordsFromApplication:andreplay 被调用了吗?
  • NO , Bebug 没有出现在这个方法中,也没有出现在 handler 方法中。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-06-13
  • 1970-01-01
  • 1970-01-01
  • 2018-08-01
  • 1970-01-01
  • 2015-03-07
  • 1970-01-01
相关资源
最近更新 更多