watchOS发送消息未被调用



嗨,我的代码有问题,看起来发送消息由于某种原因没有被调用,谢谢

if ([[WCSession defaultSession] isReachable]) {
    NSLog(@"Initiating WCSession to Read iPhone Data");
    [[WCSession defaultSession] sendMessage:watchData replyHandler:^(NSDictionary *dataFromPhone) {

        NSLog(@"Sending Empty Write Data Array to iPhone...%@", watchData);

    }
                               errorHandler:^(NSError *error) {
                                   // Log error
                                   NSLog(@"Error: %@", error);
                               }];
} else {
    //we aren't in range of the phone, they didn't bring it on their run
    NSLog(@"Unable to connect to iPhone");
}

据我所见,这是在iOS上运行的代码,它控制是否可以访问Apple Watch,但你必须记住(当然,如果你还没有做到)用以下代码从任何一个设备启用会话,所以启用通信系统

if (WCSession.isSupported()) {
    let session = WCSession.defaultSession()
    session.delegate = self
    session.activateSession()
}

最新更新