3
votes

I'm working on a sample Apple Watch application and trying to send a command from Apple Watch to iPhone. Getting the following error message.

2015-12-21 17:44:17.942 SampleWatch WatchKit Extension[157:4572] requestRecord error: Error Domain=WCErrorDomain Code=7001 "Unknown WatchConnectivity error." UserInfo={NSUnderlyingError=0x17d51350 {Error Domain=com.apple.identityservices.error Code=23 "Timed out" UserInfo={NSUnderlyingError=0x17d4a550 {Error Domain=com.apple.ids.idssenderrordomain Code=12 "(null)"}, NSLocalizedDescription=Timed out}}, NSLocalizedDescription=Unknown WatchConnectivity error.}

Code snippet to send command from Watch to 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);
                 }
         ];
    }
}

Setting up the session as follows:

    - (void)setupWatchSession
    {
        if ([WCSession isSupported]) {

        self.session = [WCSession defaultSession];
        self.session.delegate = self;
        [self.session activateSession];

        NSLog(@"@setupWatchSession: %@", self.session);
      }
    }

The same way, the set up is done even in the iPhone as well. One way (iPhone to Apple Watch) is able to receive the command but the other way from(Apple Watch to iPhone) is resulting in an error.

2
Where in the iOS app code do you perform the WCSession's set up (appdelegate, viewcontroller's viewDidLoad, etc)?ccjensen
Similar methods are also written in AppDelegate to set up the WCSession in iOS.Dantuluri
Usually I've I've seen this error when the iOS app didn't activate its WCSession, which is why I asked. Could you post the implementation of the didReceiveMessage on the iOS side?ccjensen

2 Answers

1
votes

I'm not able to comment yet, so... You might want to replace self.session with [WCSession defaultSession] when you call sendMessage. Sometimes ARC will dealloc that var for whatever reason.

This is my code and it works for me:

 [[WCSession defaultSession] sendMessage:@{@"file":urlOut.absoluteString, @"langFrom":langFrom,@"langTo":langTo, @"data":dataFromFile } replyHandler:^(NSDictionary * _Nonnull replyMessage) {
                NSLog(@"%@",replyMessage);

                [[HistoryDemon summon] addItem:replyMessage];

                [self presentControllerWithName:@"TranslationTableView" context:nil];

            } errorHandler:^(NSError * _Nonnull error) {
                NSLog(@"%@",error);
            }];

!Note I still use watchOS 2.0 //to scared to update to 2.1 :D

One more thing, starting with watchOS 2.0 the [WCSession isSupported] is always YES, so you can skip that on the watch.

Let me know if it helped, I'll keep updating my answer, if not.