WCSession sendMessage in Xcode 7.0 (7A218) Simulator

孤街浪徒 提交于 2019-12-23 16:43:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!