错误:“消息回复时间过长"向设备手表套件 OS 2 发送消息 [英] ERROR: "Message reply took too long" sending message to device Watch kit OS 2

查看:20
本文介绍了错误:“消息回复时间过长"向设备手表套件 OS 2 发送消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从 Apple Watch 向设备发送消息时出现以下错误

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

Error Domain=WCErrorDomain Code=7012 消息回复时间过长."UserInfo={NSLocalizedDescription=消息回复时间过长.,NSLocalizedFailureReason=发生回复超时.}

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

#import 在手表和主应用程序目标中都存在,并且符合手表和设备上的委托方法

#import <WatchConnectivity/WatchConnectivity.h> is in both watch and main app targets, and conforms to delegate methods on both watch and 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

                               }];

   }

设备

在 appdelegate didFinishLaunching

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");
    }

会话确认如期开始

在设备上接收消息

- (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"];
        });

      }

更新:

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

dispatch_async(dispatch_get_main_queue(), ^{



  });
}

停止根据 ccjensen 评论收到的错误消息

Stops the error message received as per ccjensen comment

推荐答案

检查这些事情:

1/确保在手机端正确实现 WCSessionDelegate.(不知道到目前为止您是否和/或实施了多少)
特别是,确保你实现了 session(_:didReceiveMessage:replyHandler:).
2/确保您实际调用了 WCSessionDelegate 中的 replyHandler,如文档中突出显示的那样:您必须将回复块作为实现的一部分来执行." WCSessionDelegate 协议参考
3/检查完这些后,请确保在重新尝试使用手表之前运行最新版本的 iPhone 应用程序.

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.

如果这些都不起作用,那么这意味着您的 WCSessionDelegate 实现太慢,因此超时,或者您在手表和手机之间遇到了很好的老式网络问题(不太可能在 sim 中,但可能存在错误).

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).

希望这会有所帮助.

我没有提到,对方应用程序必须处于活动状态才能做出响应.这意味着,iPhone 应用程序必须至少在后台(启动一次)才能响应.如果不是,过一段时间你就会超时.

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.

这篇关于错误:“消息回复时间过长"向设备手表套件 OS 2 发送消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆