问题
I use sendMessage from iWatch (Simulator) to iOS to awake iOS app:
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);
}
But I found that sendMessage only works if iOS app counterpart is either in Background or Foreground. If iOS app is not running at all, sendMessage cannot awake the iOS App. Both replyHandler and errorHandler were not called if App is not running in background / foreground.
This does not agree with the documentation: Calling this method from your WatchKit extension while it is active and running wakes up the corresponding iOS app in the background and makes it reachable. Calling this method from your iOS app does not wake up the corresponding WatchKit extension.
I tested on Xcode Beta 5 and the same piece of code worked even if iOS app is not running.
Anyone encounter similar issues in latest Simulator and Xcode? Any thoughts?
Thanks
来源:https://stackoverflow.com/questions/32553555/wcsession-sendmessage-in-xcode-7-0-7a218-simulator