Ios openParentApplication未响应Watchkit扩展中的handleWatchKitExtensionRequest
我正在尝试实现apple watch扩展。我需要调用我的iPhone应用程序类方法来触发web请求。我在苹果的文档中看到了这个方法,我也在尝试同样的方法。但是这个方法没有调用Ios openParentApplication未响应Watchkit扩展中的handleWatchKitExtensionRequest,ios,objective-c,apple-watch,Ios,Objective C,Apple Watch,我正在尝试实现apple watch扩展。我需要调用我的iPhone应用程序类方法来触发web请求。我在苹果的文档中看到了这个方法,我也在尝试同样的方法。但是这个方法没有调用 - (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void(^)(NSDictionary *replyInfo))reply 在此方面的任何帮助都
- (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void(^)(NSDictionary *replyInfo))reply
在此方面的任何帮助都将不胜感激。
以下是我的代码片段:
#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应用程序名称)。您必须在进程完成之前快速执行此操作,否则它将不会触发断点。在您的应用程序代理中,您正在使用键
requestString
检查对象,而该对象已使用键requestString
存储在字典中。此外,如果我使用任何示例应用程序从iPhone app delegate类获取数据,则需要返回除nil
以外的内容。即使我把断点也放进去,它也不会去那个里@Schemetrical@RajuIstalla我知道,这就是为什么您需要附加到进程以使断点跳闸。如果应用程序没有返回任何内容,那么您手机上的代码就有问题(除非您快速连接,否则它不会告诉您)