我使用从 iWatch(模拟器)到 iOS 的 sendMessage 来唤醒 iOS 应用程序:
NSDictionary *userInfo = [[NSDictionary alloc]initWithObjectsAndKeys:@"userInfo", @"key", nil];
if ([[WCSession defaultSession] isReachable]){ //iPhone is reachable
NSLog(@"iPhone is reachable");
[[WCSession defaultSession] sendMessage:userInfo replyHandler:^(NSDictionary<NSString *,id> * _Nonnull replyMessage) {
NSLog(@"ReplyHandler run");
} errorHandler:^(NSError * _Nonnull error) {
NSLog(@"iWatch sendMessage Error: %@", error);
}
但我发现 sendMessage 仅当 iOS 应用程序对应项位于后台或前台时才有效。如果iOS应用程序根本没有运行,则sendMessage无法唤醒iOS应用程序。如果应用程序没有在后台/前台运行,则replyHandler和errorHandler都不会被调用。
这不符合文档 https://developer.apple.com/library/prerelease/watchos/documentation/WatchConnectivity/Reference/WCSession_class/index.html#//apple_ref/occ/instm/WCSession/sendMessage:replyHandler:errorHandler::在 WatchKit 扩展处于活动状态并运行时从该扩展调用此方法会唤醒后台相应的 iOS 应用程序并使其可访问。从 iOS 应用程序调用此方法不会唤醒相应的 WatchKit 扩展。
我在 Xcode Beta 5 上进行了测试,即使 iOS 应用程序未运行,同一段代码也可以工作。
有人在最新的模拟器和 Xcode 中遇到类似的问题吗?
有什么想法吗?
Thanks
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)