在 Watchkit Extension 中打开不响应句柄监视工具包扩展请求的父应用程序



我正在尝试实现Apple Watch Extension。我需要调用我的 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

这是我的代码片段:

#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;
}

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

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

在应用程序委托中,当对象已使用键theRequestString存储在字典中时,您将使用键requestString检查对象。此外,您需要返回除nil以外的内容。

最新更新