Skip to content

开关锁示例 ​

开锁示例 ​

开锁流程图 ​

img

开锁代码 ​

* 蓝牙开锁只能近距离(距离锁10米左右),如果想异地远程开锁,可以借助“网关“

c
/*开锁*/
[TTLock controlLockWithControlAction:TTControlActionUnlock lockData:_keyModel.lockData success:^{
      NSLog(@"##############  Unlock success  ##############");
    } failure:^(TTError errorCode, NSString *errorMsg) {
        NSLog(@"##############  error: %@  ##############",errorMsg);
    }];
c
/*温馨提示:我们建议您在开锁成功后读取锁内最近一段时间的操作记录,并校准一次锁时间*/
 
- (void)unlockThenGetLogThenSetTime{
 
     //开锁
    [TTLock controlLockWithControlAction:TTControlActionUnlock lockData:lockData success:^(long long lockTime, NSInteger electricQuantity, long long uniqueId) {
        NSLog(@"##############  Unlock successed power: %ld  ##############",(long)electricQuantity);
    } failure:^(TTError errorCode, NSString *errorMsg) {
        NSLog(@"##############  Unlock failed errorMsg: %@  ##############",errorMsg);
    }];
 
     //读取操作记录 ,并上传到服务器
    [TTLock getOperationLogWithType:TTOperateLogTypeLatest lockData:lockData success:^(NSString *operateRecord) {
        //上传服务器
        //[Network uploadLog:operateRecord completion:nil];
        NSLog(@"##############  Log: %@  ##############",operateRecord);
    } failure:^(TTError errorCode, NSString *errorMsg) {
        NSLog(@"##############  Get log failed errorMsg: %@  ##############",errorMsg);
    }];
 
     //校准锁时间
    //时间戳 timestamp(毫秒) 从服务器获取
    [TTLock setLockTimeWithTimestamp:timestamp lockData:lockData success:^{
        NSLog(@"##############  Set time successed  ##############");
    } failure:^(TTError errorCode, NSString *errorMsg) {
        NSLog(@"##############  Set time failed errorMsg: %@  ##############",errorMsg);
    }];
}