【问题标题】:To openParentApplication not responding handleWatchKitExtensionRequest in Watchkit Extension在 Watchkit Extension 中 openParentApplication 没有响应 handleWatchKitExtensionRequest
【发布时间】:2015-04-15 07:18:57
【问题描述】:

我正在尝试实现 Apple Watch 扩展。我需要调用我的 iPhone 应用程序类方法来触发 Web 请求。我在苹果文档中看到了这个方法,我也在尝试。但是这个方法没有调用

- (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void(^)(NSDictionary *replyInfo))reply

对此的任何帮助表示赞赏。 https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/index.html

这是我的代码 sn-p:

#import "InterfaceController.h"

- (void)awakeWithContext:(id)context {
    [super awakeWithContext:context];

    // Configure interface objects here.
    NSString *requestString = [NSString  stringWithFormat:@"callMyRequest"];
    NSDictionary *applicationData = [[NSDictionary alloc] initWithObjects:@[requestString] forKeys:@[@"theRequestString"]];

    [WKInterfaceController openParentApplication:applicationData reply:^(NSDictionary *replyInfo, NSError *error) {
        NSLog(@"\nReply info: %@\nError: %@",replyInfo, error);
    }];
}

#import "Appdelegate.h"
#import "MyController.h"

- (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void(^) (NSDictionary *replyInfo))reply {
    NSString * request = [userInfo objectForKey:@"requestString"];

    if ([request isEqualToString:@"callMyRequest"]) {
        // Do whatever you want to do when sent the message. For instance...
        MyController*  myController = [[MyController alloc] init];
        [myController callMyRequest];
    }

    reply nil;
}

【问题讨论】:

    标签: ios objective-c apple-watch


    【解决方案1】:

    你必须回复一些东西。 reply(@{});

    此外,正在调用该方法,我只是不确定您是否知道如何调试应用程序。您需要转到调试>附加到进程>您的应用程序名称(不是 watchkit 应用程序名称)。您必须在进程完成之前快速执行此操作,否则它不会触发您的断点。

    【讨论】:

    • 如果我关注任何示例应用程序,我将从我的 iPhone 应用程序委托类获取数据。即使我设置了断点,它也不会去那里。 @Schemetrical
    • @RajuIstalla 我知道,这就是为什么您需要附加到进程以使断点跳闸。如果应用程序没有返回任何内容,则说明您手机上的代码有问题(除非您连接得足够快,否则它不会告诉您)
    【解决方案2】:

    在您的应用程序委托中,您正在使用键 requestString 检查对象,而该对象已使用键 theRequestString 存储在字典中。此外,您需要返回 nil 以外的其他内容。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多