【发布时间】:2015-04-15 07:18:57
【问题描述】:
我正在尝试实现 Apple Watch 扩展。我需要调用我的 iPhone 应用程序类方法来触发 Web 请求。我在苹果文档中看到了这个方法,我也在尝试。但是这个方法没有调用
- (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void(^)(NSDictionary *replyInfo))reply
这是我的代码 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