Objective c WCSession未响应WatchKit连接目标-C
我正在尝试使用WCSession将一些数据从Apple Watch发送到iPhone。这是发送消息的代码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 *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吗?是的,在会话被激活之前,你的代理不会收到任何代理回调