Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c WCSession未响应WatchKit连接目标-C_Objective C_Xcode_Watchkit - Fatal编程技术网

Objective c WCSession未响应WatchKit连接目标-C

Objective c WCSession未响应WatchKit连接目标-C,objective-c,xcode,watchkit,Objective C,Xcode,Watchkit,我正在尝试使用WCSession将一些数据从Apple Watch发送到iPhone。这是发送消息的代码 WCSession *session = [WCSession defaultSession]; session.delegate = self; [session activateSession]; NSDictionary *dict = @{@"time": [NSString stringWithFormat:@"%i", self.seconds], @"distance": [

我正在尝试使用WCSession将一些数据从Apple Watch发送到iPhone。这是发送消息的代码

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

NSDictionary *dict = @{@"time": [NSString stringWithFormat:@"%i", self.seconds], @"distance": [NSString stringWithFormat:@"%f", self.distance], @"splits": self.splitsArray, @"max": [NSString stringWithFormat:@"%f", hightest]};

//save data to iphone
[[WCSession defaultSession] sendMessage:dict
                           replyHandler:^(NSDictionary *reply) {
                               //handle reply from iPhone app here
                           }
                           errorHandler:^(NSError *error) {
                               NSLog(@"error %@", error);
                           }
 ];
这是AppDelegate中WCSession委托的代码

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

    NSLog(@"recieved message %@", message);

}
#pragma标记-WCsession代表
-(void)session:(非null WCSession*)session didReceiveMessage:(非null NSDictionary*)message replyHandler:(非null void(^)(NSDictionary*\uu nonnull))replyHandler{
NSLog(@“已接收消息%@”,消息);
}

日志显示该消息是从Apple Watch发送的,没有任何问题,但是,
received message
从未被记录。iphone似乎没有回应苹果手表发出的信息。这个案子有什么问题?谢谢大家!

确保在后台启动iOS应用程序时,在iOS应用程序代码的一部分中设置委派属性并激活iOS应用程序中的WCSession(UIApplicationLegate的didFinishLaunchingWithOptions是个不错的地方)

您是否正在iOS应用程序中激活WCSession?如果是的话,代码在哪里?哦,我不是。你是在暗示我也必须在iOS应用程序中激活WCSession吗?是的,在会话被激活之前,你的代理不会收到任何代理回调