iPhone收到的WatchOS sendMessage不一致且延迟

时间:2017-03-04 11:44:52

标签: xcode apple-watch watch-os-2

这是第一次使用WatchOS开发产品。我试图使用WCSession sendMessage发送一个值并触发该操作来触发一个动作。现在它确实有效,但它非常不一致和延迟。最初,当应用程序打开时,Apple Watch应用程序上的按钮会触发sendMessage,但它在iPhone上的任何操作都不会持续10 - 20秒。在每次按下按钮之后,它会触发iPhone上的操作,但有时需要一两秒钟,有时需要5到10秒。

这是将信息发送到iPhone:

[[WCSession defaultSession] sendMessage:message
                           replyHandler:^(NSDictionary *reply) {
                               //handle reply from iPhone app here
                           }
                           errorHandler:^(NSError *error) {
                               //catch any errors here
                           }
 ];

这是收到它的地方:

- (void)session:(nonnull WCSession *)session didReceiveMessage:(nonnull NSDictionary<NSString *,id> *)message replyHandler:(nonnull void (^)(NSDictionary<NSString *,id> * __nonnull))replyHandler {

    NSString* command = [NSString stringWithFormat:@"%@", [message objectForKey:@"message"]];

    //Use this to update the UI instantaneously (otherwise, takes a little while)
    dispatch_async(dispatch_get_main_queue(), ^{
        [self.label setText:command];
        [SampleCameraApi actTakePicture:self];
        [self progressIndicator:YES];
    });

}

现在这是非常基本的,但我只是想弄清楚为什么它如此不一致或者是否有更好的方法来解决它。发送消息并不像在iPhone上触发操作那么重要。

0 个答案:

没有答案