我正在尝试实现 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
这是我的代码片段:
#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;
}
最佳答案
你必须回复一些东西。 回复(@{});
此外,正在调用该方法,我只是不确定您是否知道如何调试该应用程序。您需要转到“调试”>“附加到进程”>“您的应用程序名称”(不是 watchkit 应用程序名称)。您必须在该过程完成之前快速执行此操作,否则它不会触发您的断点。
关于ios - openParentApplication 不响应 Watchkit Extension 中的 handleWatchKitExtensionRequest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29643926/