我看到有关错误4的报告,但没有关于5的报告。当我尝试使用"openParentApplication:reply"请求时,我会在控制台上收到此消息。日志中没有足够的信息可以确定问题是在iOS代码、WK代码还是模拟器中。我已经重启了模拟器并清理了项目。有什么想法吗?
WK代码:
- (IBAction)sendRequest {
NSDictionary *request = @{@"request":@"Request1"};
[InterfaceController openParentApplication:request reply:^(NSDictionary *replyInfo, NSError *error) {
if (error) {
NSLog(@"%@", error);
} else {
[self.label1 setText:[replyInfo objectForKey:@"response1"]];
[self.label2 setText:[replyInfo objectForKey:@"response2"]];
[self.label3 setText:[replyInfo objectForKey:@"response3"]];
}
}];
}
iOS 代码:
- (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void (^)(NSDictionary *))reply{
NSLog(@"%s", __FUNCTION__);
//([max intValue] - [min intValue]) + [min intValue]
int randNum1 = arc4random_uniform(16);
int randNum2 = arc4random_uniform(16);
int randNum3 = arc4random_uniform(16);
NSString *num1 = [NSString stringWithFormat:@"Test%d", randNum1];
NSString *num2 = [NSString stringWithFormat:@"Test%d", randNum2];
NSString *num3 = [NSString stringWithFormat:@"Test%d", randNum3];
if ([[userInfo objectForKey:@"request"] isEqualToString:@"Request1"]) {
NSLog(@"containing app received message from watch: Request1");
NSDictionary *response = @{@"response1" : num1, @"response2" : num2, @"response3" : num3};
reply(response);
}
}
唯一的控制台日志是:
WatchKit Extension[48954:9523373] Error Domain=FBSOpenApplicationErrorDomain Code=5 "The operation couldn’t be completed. (FBSOpenApplicationErrorDomain error 5.)