SocketScan始终返回100%的电池寿命

时间:2016-06-16 20:05:32

标签: ios socketscan

我每次都得到100%的结果......为什么(iOS / SocketScan API v.10.2.227)? 这是我的代码:

-(void) onGetBatteryInfo:(ISktScanObject*)scanObj {

    SKTRESULT result=[[scanObj Msg]Result];
    if(SKTSUCCESS(result)){

        long batteryLevel = SKTBATTERY_GETCURLEVEL([[scanObj Property] getUlong]);
        NSLog(@"BatteryInfo %ld", batteryLevel);

        [self setBatteryLevel:batteryLevel];
        [self.tableView reloadData];

    } else {

        NSLog(@"ES-GetBatteryInfo set status returned the error %ld",result);
    }
}

谢谢, 标记

scanner config

1 个答案:

答案 0 :(得分:1)

你能仔细检查以下内容......

viewDidLoad中,您可以创建ScanApiHelper和计时器

if(ScanApi==nil) {
    ScanApi=[[ScanApiHelper alloc]init];
    [ScanApi setDelegate:self];
    [ScanApi open];
    ScanApiConsumer=[NSTimer scheduledTimerWithTimeInterval:.2 target:self selector:@selector(onTimer:) userInfo:nil repeats:YES];
}

您的计时器调用doScanApiReceive

-(void)onTimer: (NSTimer*)theTimer{
    if(theTimer==ScanApiConsumer){
        [ScanApi doScanApiReceive];
    }
}

最后,在收到onDeviceArrival通知

之前,您不会查询电池电量
-(void)onDeviceArrival:(SKTRESULT)result device:(DeviceInfo*)deviceInfo {
    [ScanApi postGetBattery:deviceInfo Target:self Response:@selector(onGetBatteryInfo:)];
}