我正在研究样本Apple Watch应用程序并尝试从Apple Watch向iPhone发送命令。 收到以下错误消息。
2015-12-21 17:44:17.942 SampleWatch WatchKit Extension [157:4572] requestRecord error:Error Domain = WCErrorDomain Code = 7001" Unknown WatchConnectivity错误。"的UserInfo = {NSUnderlyingError = 0x17d51350 {Error Domain = com.apple.identityservices.error Code = 23" Timed out" UserInfo = {NSUnderlyingError = 0x17d4a550 {错误 Domain = com.apple.ids.idssenderrordomain Code = 12"(null)"}, NSLocalizedDescription =超时}},NSLocalizedDescription =未知 WatchConnectivity错误。}
从Watch发送命令到iPhone的代码片段:
- (void)sendCommand
{
NSLog(@" ### SendCommand :%d ###",[self.session isReachable] );
if ([self.session isReachable]) {
NSDictionary *message = @{@"Command": @"Hello"};
[self.session sendMessage:message
replyHandler:^(NSDictionary *reply) {
//handle reply from iPhone app here
NSLog(@"requestRecord reply: %@", reply);
}
errorHandler:^(NSError *error) {
//catch any errors here
NSLog(@"requestRecord error: %@", error);
}
];
}
}
按如下方式设置会话:
- (void)setupWatchSession
{
if ([WCSession isSupported]) {
self.session = [WCSession defaultSession];
self.session.delegate = self;
[self.session activateSession];
NSLog(@"@setupWatchSession: %@", self.session);
}
}
同样,即使在iPhone中也能完成设置。 一种方式(iPhone到Apple Watch)能够接收命令,但从(Apple Watch到iPhone)的另一种方式导致错误。