是否可以从 watchOS 3 应用程序唤醒 iPhone 应用程序?
Is it possible to wake up iPhone app from watchOS 3 app?
是否可以从 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];
}
}
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];
}
}
}
是否可以从 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];
}
}
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];
}
}
}