我想從Apple Watch使用WCSession向iPhone發送一些數據。以下是發送消息的代碼WCSession沒有響應WatchKit連接性Objective-C
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);
}
日誌顯示該郵件是從Apple關注沒有任何問題發送,然而,recieved message
從來沒有記錄。這似乎是iPhone沒有迴應蘋果手錶的消息。這種情況下有什麼問題?謝謝!
您是否正在iOS應用中激活WCSession?如果是這樣的代碼? – ccjensen
哦,我不是。你是否暗示我必須在iOS應用程序中激活WCSession? – NeilNie
是的,你的代表將不會收到任何委託回調,直到會話被激活 – ccjensen