iOS应用程序被杀但AppleWatch可以发送消息吗?为什么?

时间:2016-11-14 02:24:10

标签: apple-watch apple-watch-complication

  1. AppleWatch Enterforground,Watch客户端发送" @ {@"检查":@"我' m"}"
  2. iOS客户端收到" @ {@"检查":@"我' m"}" ,使用静态num i重播字典为" @ {@"检查":@" Rcheck_i"}"
  3. 杀死iOS客户端
  4. AppleWatch enterbackground,5秒,enterforround,AppleWatch从ios客户端收到消息" @ {@" check":@" Rcheck_i"}",what& #39;错了???
  5. 谁可以帮助我,代码是......

    // iOS客户端

    static int i = 0;
    - (void) session:(nonnull WCSession *)session didReceiveMessage:(nonnull NSDictionary<NSString *,id> *)message replyHandler:(nonnull void (^)(NSDictionary<NSString *,id> * __nonnull))replyHandler{
        dispatch_async(dispatch_get_main_queue(), ^{
            i++;
            NSString *temKey = [message.allKeys objectAtIndex:0];
            NSString *temStr = [NSString stringWithFormat:@"%@_%d",temKey,i];
            dispatch_async(dispatch_get_main_queue(), ^{
                self.statusLabel.text = temStr;
            });
            if([message objectForKey:@"check"]){
                NSString *temStr = [NSString stringWithFormat:@"Rcheck_%d",i];
                replyHandler(@{@"check":temStr});
            }
        });
    }
    

    // AppleWatch客户端

    static int i = 0;
    - (void)willActivate {
        [super willActivate];
        i++;
        if ([WCSession isSupported] ) {
            WCSession* session = [WCSession defaultSession];
            session.delegate = self;
            [session activateSession];
            [self performSelector:@selector(checkAction) withObject:nil afterDelay:0.1];
        }
        else{
            [self.lblLockState setText:@"WATCH NOT support"];
        }
    }
    
    - (void) checkAction{
        WCSession* session = [WCSession defaultSession];
        [session sendMessage:@{@"check":@"I'm Back"} replyHandler:^(NSDictionary<NSString *,id> * _Nonnull replyHandler) {        
            dispatch_async(dispatch_get_main_queue(), ^{
                NSString *temStr;
                if ([replyHandler objectForKey:@"check"]) {
                    temStr = [replyHandler objectForKey:@"check"] ;//[NSString stringWithFormat:@"CheckSucc_%d",i];
                }
                else{
                    temStr = [NSString stringWithFormat:@"CheckSucc??_%d",i];
                }
                [self.lblLockState setText:temStr];
            });
        } errorHandler:^(NSError * _Nonnull error) {
            dispatch_async(dispatch_get_main_queue(), ^{
                NSString *temStr = [NSString stringWithFormat:@"CheckFail_%d",i];
                [self.lblLockState setText:temStr];
            });
        }];
    }
    

0 个答案:

没有答案