是否可以从watchOS 3应用程序中唤醒iPhone应用程序?

时间:2016-11-12 23:13:49

标签: ios objective-c iphone apple-watch watch-os-3

是否可以从watchOS 3应用程序中唤醒iPhone应用程序?

代码的第一部分在watchOS 2上已经足够了,但即使代码的两个部分也无法在watchOS 3上运行:

初​​始化:

if ([WCSession isSupported]) {
    WCSession* session = [WCSession defaultSession];
    session.delegate = self;
    [session activateSession];
}

另一种方法:

if ([WCSession isSupported]) {
    WCSession* session = [WCSession defaultSession];
    if (session.reachable) { // <-- RETURNS FALSE
        NSDictionary *message = @{@"action":@"wakeup"};
        [session sendMessage:message replyHandler:nil errorHandler:nil];
    }
}

1 个答案:

答案 0 :(得分:1)

Apple建议使用以下代码:

- (void)session:(WCSession *)session activationDidCompleteWithState:(WCSessionActivationState)activationState error:(NSError *)error {
    if ([WCSession isSupported]) {
        WCSession* session = [WCSession defaultSession];
        if (session.activationState == WCSessionActivationStateActivated) {
            NSDictionary *message = @{@"action":@"wakeup"};
            [session sendMessage:message replyHandler:nil errorHandler:nil];
        }
    }
}