Latest 2.7.3
Homepage https://github.com/ttlock/iOS_TTLock_Demo
License MIT
Platforms ios 8.0, requires ARC
Frameworks CoreBluetooth
Authors

TTLock.framework

Minimum iOS Target:

iOS 8.0

Minimum Xcode Version:

  Xcode 9.0

Installation

First, add the following line to your Podfile:

pod ‘TTLock’

Second, install TTLock into your project:

pod install

Manually

1.Drag the TTLock.framework and DFUDependence.framework into your project.

2.Find the target settings in this application, then find ‘General’ -> ‘Embedded Binaries’, add the two frameworks above.

3.Find Targets->Build Settings ->Always Embed Swift Standard Libraries ,then set ‘YES’.

4.Find Targets->Build Phases -> Link Binary With Libraries ,then add the CoreBluetooth framework to your project .

Introduction

TTLockLock

TTLockLock has been designed to communicate with devices by mobile phone bluetooth.

TTLockGateway

TTLockGateway has been designed to make it easy to communicate with Wi-Fi module.

TTLockDFU (Device Firmware Upgrade)

TTLockDFU has been designed to make it easy to upgrade devices into your application by mobile phone bluetooth.

Usage

TTLockLock Usage

1.Import header file :

#import <TTLock/TTLock.h>

2.Create a singleton object for TTLock

TTLock *TTObject = [[TTLock alloc]initWithDelegate:self];   

Create a Bluetooth central object and starts Bluetooth

[TTObject setupBlueTooth];  

Do you want to open the SDK log? YES print, NO does not print, and defaults to No

[TTLock setDebug:YES]; 

3.Executing the following code in the callback of ‘TTLockManagerDidUpdateState’ what is Bluetooth state changing:

if (central.state == CBCentralManagerStatePoweredOn) {
  [TTObject startBTDeviceScan]; //start scanning
}else if (central.state == CBCentralManagerStatePoweredOff){ 
  [TTObject stopBTDeviceScan];  // stop scanning
}else if(central.state == CBCentralManagerStateUnsupported){    
  NSLog(@"Your device does not support ble4.0, unable to use our app.");   
}

4.It will execute the delegate method of ‘onFoundDevice_peripheral’ after scanning the device, you can get the basic information about the peripherals, such as, Bluetooth name, MAC address, broadcast data and so on.

5.You can connect the given Bluetooth by the way of scanning peripheral above.

[TTObject connect:peripheral];

6.It will execute the delegate method of ‘onBTConnectSuccess_peripheral’ after connecting successfully.

In this method,firstly,you should Executing the following code :

[TTObject stopBTDeviceScan];

secondly,you should Executing the following code:

TTObject.uid = openid;

lastly, you can call interface such as, add administrator, open the door, etc…

7.It can receive corresponding callback after call appropriate interface, successful callback for success, error callback for failure.

8.Executing the following code in the callback of ‘onBTDisconnect_peripheral’:

[TTObject startBTDeviceScan];

Scene: Add administrator

1.Scan devices nearby

2.Connect the lock which you want to add administrator(You can add administrator only if there is no administrator in this lock, and you can judge it by parameter ‘isContainAdmin’)

[TTObject connect:peripheral];(This parameter 'peripheral' is in the callback 'onFoundDevice_peripheralWithInfoDic')

3.After the connection is successful, you can call bluetooth interface ‘addAdministrator’.

4.Use the network interface(v3/lock/init) to upload data after receiving the callback of ‘onAddAdministrator’.

Scene: Delete the lock

The three generation lock administrators delete the lock

1、Connect the lock you want to delete, then call Bluetooth interface ‘resetLock’.

2、Call the network interface ‘v3/key/delete’ after receiving the callback ‘onResetLock’.

In addition to the three generation lock administrators

1、Call the network interface ‘v3/key/delete’ directly.

Scene: Unlock

1.Administrator calls bluetooth interface ‘unlockByAdministrator’ ,Ekey calls bluetooth interface ‘unlockByUser’ after connecting the lock which you want to open.

2.Call Bluetooth interface ‘setLockTime’ after receiving the callback of ‘onUnlockWithLockTime’.

3.Receive the callback(‘onSetLockTime’) of successful calibrate the time.

Notes

TTLockLock Notes

1.If you need to call many bluetooth interfaces at the same time ,you must call the following interface after the previous interface callback.

Such as,you want to unlock ,and calibrate time.  

Wrong demonstration

-(void)onBTConnectSuccess_peripheral:(CBPeripheral )peripheral lockName:(NSString)lockName{

 // unlock

[TTObject unlockByUser_lockKey:lockKey aesKey:aesKeyStr startDate:startDate endDate:endDate version:version unlockFlag:unlockFlag uniqueid:uniqueid timezoneRawOffset:timezoneRawOffset];

//calibrate time

[TTObject setLockTime_lockKey:lockKey aesKey:aesKeyStr version:version unlockFlag:unlockFlag referenceTime:referenceTime timezoneRawOffset:timezoneRawOffset];

}

Correct demonstration

“`objective-c  
-(void)onBTConnectSuccess_peripheral:(CBPeripheral )peripheral lockName:(NSString)lockName{

// unlock
[TTObject unlockByUser_lockKey:lockKey aesKey:aesKeyStr startDate:startDate endDate:endDate version:version unlockFlag:unlockFlag uniqueid:uniqueid timezoneRawOffset:timezoneRawOffset];

}

//after receiving the callback of unlock successfully
-(void)onUnlockWithLockTime:(NSTimeInterval)lockTime{

//calibrate time
[TTObject setLockTime_lockKey:lockKey aesKey:aesKeyStr version:version unlockFlag:unlockFlag referenceTime:referenceTime timezoneRawOffset:timezoneRawOffset];

}

  

2.The callback for ‘onFoundDevice_peripheral’ will scan all supported devices nearby, just connect which you really need.

3.All callbacks in the TTLockLock are in the child thread.

4.In order to record who operates the lock,you should assign values to attributes 'uid' before Sending instruction in the callback 'onBTConnectSuccess_peripheral'. 
```objective-c  
TTObject.uid = openid; 

Latest podspec

{
    "name": "TTLock",
    "version": "2.7.3",
    "summary": "TTLock SDK for iOS.",
    "homepage": "https://github.com/ttlock/iOS_TTLock_Demo",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "ttlock": "[email protected]"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/ttlock/iOS_TTLock_Demo.git",
        "tag": "2.7.3"
    },
    "vendored_frameworks": "TTLockFrameworks/TTLock.framework",
    "preserve_paths": "TTLockFrameworks/TTLock.framework",
    "frameworks": "CoreBluetooth",
    "libraries": "z",
    "requires_arc": true
}

Pin It on Pinterest

Share This