我正在开发一个样例的Apple Watch应用程序,并试图从Apple Watch向iPhone发送命令。但是出现了以下错误信息:
同样的,即使是在iPhone上也可以进行设定。其中一种方式(从iPhone到Apple Watch)可以接收指令,但另一种方式(从Apple Watch到iPhone)会出现错误。
以下是从Watch向iPhone发送命令的代码片段:2015-12-21 17:44:17.942 SampleWatch WatchKit Extension[157:4572] requestRecord error: Error Domain=WCErrorDomain Code=7001 "未知的WatchConnectivity错误。" UserInfo={NSUnderlyingError=0x17d51350 {Error Domain=com.apple.identityservices.error Code=23 "超时" UserInfo={NSUnderlyingError=0x17d4a550 {Error Domain=com.apple.ids.idssenderrordomain Code=12 "(null)"}, NSLocalizedDescription=超时}}, NSLocalizedDescription=未知的WatchConnectivity错误。}
- (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)会出现错误。