在Xcode 7.0(7A218)模拟器中的WCSession sendMessage

时间:2015-09-13 19:13:59

标签: ios objective-c xcode watchkit

我使用iWatch(模拟器)的sendMessage到iOS来唤醒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 app对应的是Background或Foreground时才有效。如果iOS应用程序根本没有运行,则sendMessage无法唤醒iOS应用程序。如果App未在后台/前台运行,则不会调用replyHandler和errorHandler。

这与documentation不一致:在WatchKit扩展程序处于活动状态时调用此方法,并在后台运行相应的iOS应用程序并使其可访问。从iOS应用程序调用此方法不会唤醒相应的WatchKit扩展。

我在Xcode Beta 5上进行了测试,即使iOS应用程序没有运行,相同的代码也能正常运行。

在最新的Simulator和Xcode中遇到过类似的问题吗? 有什么想法吗?

由于

0 个答案:

没有答案