new update bd7bc4b
ttlock-developers-email-list@googlegroups.com
yarn add react-native-ttlock
cd ./ios && pod install && cd ../
TARGETS
➜ info
➜ add key Privacy - Bluetooth Peripheral Usage Description
value your description for bluetooth
and key Privacy - Bluetooth Always Usage Description
value your description for bluetooth
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
android 12 needs below permission.
<!--
Needed only if your app looks for Bluetooth devices.
You must add an attribute to this permission, or declare the
ACCESS_FINE_LOCATION permission, depending on the results when you
check location usage in your app.
-->
<uses-permission
android:name="android.permission.BLUETOOTH_SCAN"
android:usesPermissionFlags="neverForLocation"
tools:targetApi="s" />
<!--
Needed only if your app makes the device discoverable to Bluetooth
devices.
-->
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
<!--
Needed only if your app communicates with already-paired Bluetooth
devices.
-->
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
ReactInstanceManager mReactInstanceManager = getReactNativeHost().getReactInstanceManager();
TtlockModule ttlockModule = mReactInstanceManager.getCurrentReactContext().getNativeModule(TtlockModule.class);
ttlockModule.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
repositories {
buildTypes {
release {
minifyEnabled false
shrinkResources false
}
}
defaultConfig {
minSdkVersion 18
}
1.0 Get bluetooth state
Ttlock.getBluetoothState((state: BluetoothState)=>{
console.log("bluetooth:",state);
});
1.1 Scan lock
//Start scan lock
android 12 needs request android.permission.BLUETOOTH_SCAN before Ttlock.startScan
Ttlock.startScan((scanLockModal: ScanLockModal) => {
//todo
});
//Stop scan lock
Ttlock.stopScan();
1.2 Init lock
android 12 needs android.permission.BLUETOOTH_CONNECT permission before calling apis.
All apis needs android.permission.BLUETOOTH_CONNECT permission
const param = {
lockMac: scanLockModal.lockMac,
lockVersion: scanLockModal.lockVersion
}
Ttlock.initLock(param, (lockData) => {
Ttlock.stopScan();
//...
}, (errorCode, errorDesc) => {
//...
})
}
1.3 Reset Lock
Ttlock.resetLock(lockData, () => {
//...
}, (errorCode, errorDesc) => {
//...
})
1.4 Set Lock Time
let timestamp = new Date().getTime();
Ttlock.setLockTime(timestamp, lockData, () => {
//...
}, (errorCode, errorDesc) => {
//...
});
1.5 Get Lock Time
Ttlock.getLockTime(lockData, (lockTimestamp: number) => {
//...
}, (errorCode, errorDesc) => {
//...
});
1.6 Get Lock Operation Record
Ttlock.getLockOperationRecord(LockRecordType.Latest, lockData, successCallback, failedCallback);
1.7 Get Lock State
Ttlock.getLockSwitchState(lockData, (state: LockState) => {
//...
}, (errorCode, errorDesc) => {
//...
});
1.8 Set lock automatic locking periodic time
let seconds = 20;
Ttlock.setLockAutomaticLockingPeriodicTime(seconds, lockData, () => {
//...
}, (errorCode, errorDesc) => {
//...
});
1.9 Get lock automatic locking periodic time
Ttlock.getLockAutomaticLockingPeriodicTime(lockData, (currentTime: number, maxTime: number, minTime: number) => {
//...
}, (errorCode, errorDesc) => {
//...
});
1.10 Set lock remote unlock switch state
let isOn = true;
Ttlock.setLockRemoteUnlockSwitchState(isOn, lockData, (lockDataNew: string) => {
let text = "set lock remote unlock switch success, please upload lockDataNew to server";
console.log(text);
}, (errorCode, errorDesc) => {
//...
});
1.11 Set lock config
/*
enum LockConfigType {
Audio = 0,
PasscodeVisible = 1,
Freeze = 2,
TamperAlert = 3,
ResetButton = 4,
PrivacyLock = 5
}
*/
let isOn = true;
Ttlock.setLockConfig(LockConfigType.Audio, isOn, lockData, () => {
let text = "config lock success";
successCallback(text);
}, (errorCode, errorDesc) => {
//...
});
1.12 Get lock config
/*
enum LockConfigType {
Audio = 0,
PasscodeVisible = 1,
Freeze = 2,
TamperAlert = 3,
ResetButton = 4,
PrivacyLock = 5
}
*/
Ttlock.getLockConfig(LockConfigType.Audio, lockData, (type: number, isOn: boolean) => {
let text = "type:" + type + "\n" + "isOn:" + isOn;
successCallback(text);
}, (errorCode, errorDesc) => {
//...
});
2.1 Control lock
Ttlock.controlLock(LockControlType.Unlock, lockData, (lockTime: number, electricQuantity: number, uniqueId: number) => {
let text = "lockTime:" + lockTime + "\n" + "electricQuantity:" + electricQuantity + "\n" + "uniqueId:" + uniqueId;
successCallback(text);
}, (errorCode, errorDesc) => {
//...
});
2.2 Reset ekey
Ttlock.resetEkey(lockData, (lockDataNew) => {
//important: upload lockDataNew to ttlock server.
let text = "reset ekey success";
console.log(text);
}, (errorCode, errorDesc) => {
//...
});
3.1 Get passcode https://open.sciener.com/doc/api/v3/keyboardPwd/get 3.2 Custom passcode
//example: passcode valid one day
let startDate = new Date().getTime();
let endDate = startDate + 24 * 3600 * 1000;
Ttlock.createCustomPasscode("1122", startDate, endDate, lockData, () => {
successCallback("create cutome passcode success");
}, (errorCode, errorDesc) => {
//...
});
3.3 Modify passcode
// passcode valid one minute
let startDate = new Date().getTime();
let endDate = startDate + 1 * 60 * 1000;
let oldPasscode = "1122";
let newPasscode = "2233";
Ttlock.modifyPasscode(oldPasscode, newPasscode, startDate, endDate, lockData, () => {
successCallback("modify passcode success");
}, (errorCode, errorDesc) => {
//...
});
3.4 Delete passcode
Ttlock.deletePasscode("2233", lockData, () => {
successCallback("delete passcode success");
}, (errorCode, errorDesc) => {
//...
});
3.5 Reset all passcode ( not contain the admin password )
Ttlock.resetPasscode(lockData, (lockDataNew: string) => {
//important: upload lockDataNew to ttlock server.
console.log("reset passcode success, please upload lockDataNew to server");
}, (errorCode, errorDesc) => {
//...
});
3.6 Modify admin passcode
let adminPasscode = "9999";
Ttlock.modifyAdminPasscode(adminPasscode, lockData, () => {
let text = "modify admin passcode success";
}, (errorCode, errorDesc) => {
//...
});
4.1 Add card
// card valid one day
let startDate = new Date().getTime();
let endDate = startDate + 24 * 3600 * 1000;
Ttlock.addCard(null, startDate, endDate, lockData, () => {
// progress
}, (cNumber: string) => {
cardNumber = cNumber;
let text = "cardNumber:" + cardNumber;
successCallback(text);
}, (errorCode, errorDesc) => {
//...
});
4.2 Modify card validity period
// card valid one minute
let startDate = new Date().getTime();
let endDate = startDate + 1 * 60 * 1000;
Ttlock.modifyCardValidityPeriod(cardNumber, null, startDate, endDate, lockData, () => {
let text = "modify card validity period success";
}, (errorCode, errorDesc) => {
//...
});
4.3 Delete card
Ttlock.deleteCard(cardNumber, lockData, () => {
let text = "delete card success";
}, (errorCode, errorDesc) => {
//...
});
4.4 Clear all cards
Ttlock.clearAllCards(lockData, () => {
let text = "clear all cards success";
}, (errorCode, errorDesc) => {
//...
});
5.1 Add fingerprint
// card valid one day
let startDate = new Date().getTime();
let endDate = startDate + 24 * 3600 * 1000;
Ttlock.addFingerprint(null, startDate, endDate, lockData, (currentCount: number, totalCount: number) => {
let text = "currentCount:" + currentCount + "\n" + "totalCount:" + totalCount;
progressCallback(text);
}, (fNumber: string) => {
fingerprintNumber = fNumber;
let text = "fingerprintNumber:" + fingerprintNumber
}, (errorCode, errorDesc) => {
//...
});
5.2 Modify fingerprint validity period
// fingerprint valid one minute
let startDate = new Date().getTime();
let endDate = startDate + 1 * 60 * 1000;
Ttlock.modifyFingerprintValidityPeriod(fingerprintNumber, null, startDate, endDate, lockData, () => {
let text = "modify fingerprint validity period success";
}, (errorCode, errorDesc) => {
//...
});
5.3 Delete fingerprint
Ttlock.deleteFingerprint(fingerprintNumber, lockData, () => {
let text = "delete fingerprint success";
}, (errorCode, errorDesc) => {
//...
});
5.4 Clear all fingerprints
Ttlock.clearAllFingerprints(lockData, () => {
let text = "clear all fingerprints success";
}, (errorCode, errorDesc) => {
//...
});
6.1 Add passage mode
//valid time 8:00 am --- 17:00 pm
let startTime = 8 * 60;
let endTime = 17 * 60;
Ttlock.addPassageMode(LockPassageMode.Weekly, [1, 2, 7], startTime, endTime, lockData, () => {
let text = "add passage mode success";
}, (errorCode, errorDesc) => {
//...
});
6.2 Clear all passageModes
Ttlock.clearAllPassageModes(lockData, () => {
let text = "clear all passage modes success";
}, (errorCode, errorDesc) => {
//...
});
7.1 Wifi lock scan nearby wifi
Ttlock.scanWifi(lockData, (isFinished: boolean, wifiList: []) => {
}, (errorCode, errorDesc) => {
//...
});
7.2 Wifi lock config wifi
const wifiName = 'sciener'
const wifiPassword = 'sciener.com'
Ttlock.configWifi(wifiName, wifiPassword, lockData, () => {
let text = "config lock wifi success";
}, (errorCode, errorDesc) => {
//...
});
7.3 Wifi lock config server
const serverIp = "121.196.45.110"
const serverPort = "4999"
Ttlock.configServer(serverIp, serverPort, lockData, () => {
let text = "config lock wifi ip address success";
}, (errorCode, errorDesc) => {
//...
});