我想让我的手表应用程序响应手机上的父应用程序被杀死。当手表应用程序正在运行并且电话应用程序被终止时,我没有收到来自sessionReachabilityDidChange
或的回调sessionWatchStateDidChange
。基于苹果文档:
调用此方法是为了让当前进程知道其对应会话的可达性发生了变化。
所以,看来我应该得到一个回调。我已经在手表上将 WCSession 代表设置为我的班级。手表上的会话接收应用程序上下文的回调。为什么我没有收到可达性回调?
下面的代码..
+ (SomeClass *)sharedInstance {
static dispatch_once_t pred;
static SomeClass *shared = nil;
dispatch_once(&pred, ^{
shared = [[SomeClass alloc] init];
[Model sharedInstance].delegate = shared;
});
return shared;
}
#pragma mark - setup
- (void)initializeSession {
if ([WCSession isSupported]) {
WCSession *session = [WCSession defaultSession];
session.delegate = self;
[session activateSession];
[self sync];
}
}
-(BOOL) hasValidWCSession {
return ([WCSession isSupported] && [WCSession defaultSession].isReachable);
}
#pragma mark - WCSessionDelegate
- (void)session:(nonnull WCSession *)session didReceiveApplicationContext:(nonnull NSDictionary<NSString *, id> *)applicationContext {
NSLog(@"application context received on watch: %@", applicationContext);
[[Model sharedInstance] process:applicationContext];
}
- (void)sessionWatchStateDidChange:(WCSession *)session {
NSLog(@"wcession state changed on watch");
}
- (void)sessionReachabilityDidChange:(WCSession *)session {
NSLog(@"wcsession reachability changed on watch");
}