Dmitry
Dmitry

Reputation: 14622

Is it possible to wake up iPhone app from watchOS 3 app?

Is it possible to wake up iPhone app from watchOS 3 app?

The first part of the code was enough on watchOS 2 but even the both parts of the code don't work on watchOS 3:

Initialization:

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

On another method:

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

Upvotes: 3

Views: 901

Answers (1)

Dmitry
Dmitry

Reputation: 14622

Apple suggested the following code:

- (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];
        }
    }
}

Swift version:

guard WCSession.isSupported() else {
    return
}
let session = WCSession.default
if session.activationState != .notActivated {
    session.activate()
}
if session.activationState == .activated {
    let message = ["action":"wakeup"]
    session.sendMessage(message, replyHandler: nil)
}

Upvotes: 1

Related Questions