ERROR: “Message reply took too long” sending message to device Watch kit OS 2

£可爱£侵袭症+ 提交于 2019-12-23 12:36:37

问题


Im getting the following error when sending a message from Apple Watch to device

Error Domain=WCErrorDomain Code=7012 "Message reply took too long." UserInfo={NSLocalizedDescription=Message reply took too long., NSLocalizedFailureReason=Reply timeout occured.}

#import <WatchConnectivity/WatchConnectivity.h> is in both watch and main app targets, and conforms to delegate methods on both watch and device

SEND MESSAGE FROM WATCH TO DEVICE

  • Session confirmed as Available
  • Session confirmed as Reachable

    NSDictionary *applicationDict = [[NSDictionary alloc] initWithObjects:@[@"SomethingHere"] forKeys:@[@"valueKey"]];
    
    if([[WCSession defaultSession] isReachable]) {
        NSLog(@"Reachable"); //<---- Console shows reachable
    
        [[WCSession defaultSession] sendMessage:applicationDict
                                    replyHandler:^(NSDictionary *reply) {
    
                                       NSLog(@"%@",reply);
    
                                   }
    
                                   errorHandler:^(NSError *error) {
    
                                       NSLog(@"%@",error); //<--- returns error
    
                                   }];
    
       }
    

DEVICE

In appdelegate didFinishLaunching

    // Watch kit session
    if ([WCSession isSupported]) {
        WCSession *session = [WCSession defaultSession];
        session.delegate = self;
        [session activateSession];
        NSLog(@"\n\n - WatchKit Session Started - \n\n");
    }
    else{
        NSLog(@"WatchKit Session Error");
    }

Session confirmed as starting as expected

Receiving Message On Device

- (void)session:(nonnull WCSession *)session didReceiveMessage:(nonnull NSDictionary<NSString *,id> *)message replyHandler:(nonnull void (^)(NSDictionary<NSString *,id> * __nonnull))replyHandler {
        NSLog(@"Data delagte");
        dispatch_async(dispatch_get_main_queue(), ^{
            resultFromWatch = [message objectForKey:@"resultDataValue"];
        });

      }

Update:

- (void) session:(nonnull WCSession *)session didReceiveApplicationContext:(nonnull NSDictionary<NSString *,id> *)message {

dispatch_async(dispatch_get_main_queue(), ^{



  });
}

Stops the error message received as per ccjensen comment


回答1:


Check these things:

1/ Make sure to implement the WCSessionDelegate properly on the phone side. (No idea if and/or how much you implemented so far)
In particular, make sure you implemented session(_:didReceiveMessage:replyHandler:).
2/ Make sure that you actually call the replyHandler in the WCSessionDelegate as highlighted in the doc: "You must execute the reply block as part of your implementation." WCSessionDelegate Protocol Reference
3/ Once you've checked these, make sur you run the latest version of the iPhone app before re-trying with the watch.

If these don't work, then it means your WCSessionDelegate implementation is too slow and therefore times out or you get a good old fashion network issue between the watch and the phone (unlikely in the sim, but bugs are possible).

Hope this helps.

Edit: I missed to mention, that the counter part app must be active for it to respond. It means, the iPhone app must be at least in the background (launched once) for it to respond. If it isn't, and after a while you will get a timeout.




回答2:


Make sure you set WCSession delegate before you active the session.



来源:https://stackoverflow.com/questions/32279740/error-message-reply-took-too-long-sending-message-to-device-watch-kit-os-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!