Door Lock SDK Use
1. Overview
This article mainly introduces how to use the door lock SDK for network access and device control.
2. Preconditions
- Complete Preparation
- Complete Environment Build
- Complete Door Lock SDK Integration
3. Use
The door lock SDK supports different devices in the form of RN plug-ins, and each device has a separate plug-in file.
3.1 SDK configuration
In the place where the APP starts (e.g. AppDelegate), import the header files and complete initialization as follows. See Environment Build for how to obtain each parameter.
#import <LMFramework/LMFramework.h>
#import <LMRnFramework/LMRnFramework.h>
Unified initialization
/**
The following two settings must be configured first, in order, and before any other SDK initialization.
setAppChannel and setAppGroupId must match the host app configuration.
*/
[LMOpenSDK setAppChannel:@"Your AppChannel"];
[LMOpenSDK setAppGroupId:@"Your AppGroupId"];
LMRegionModel *regionModel = [[LMRegionModel alloc] init];
regionModel.appId = @"Your appId";
regionModel.appKey = @"Your appKey";
regionModel.supportDeviceArea = @"Your SupportDeviceArea";
regionModel.serverCode = @"Your ServerCode";
regionModel.countryCode = @"Your CountryCode";
regionModel.server = @"Your Server";
regionModel.coapServer = @"Your CoapServer";
regionModel.staticsResPrefix = @"Your StaticsResPrefix";
regionModel.appImgPrefix = @"Your AppImgPrefix";
[LMOpenSDK setRegionModel:regionModel];
[LMOpenSDK setH5UrlPrefix:@"Your H5UrlPrefix"];
/**
setLanguage:
"en" English
"ru" Russian
"ko" Korean
"zh-Hans" Simplified Chinese
"zh-HK" Traditional Chinese (Hong Kong)
"zh-Hant-TW" Traditional Chinese (Taiwan)
*/
[LMOpenSDK setLanguage:@"zh-Hans"];
[LMOpenSDK setUserId:@"Your UserId" token:@"Your AccessToken"];
/**
Initialize RN Bridge — required for the door lock SDK
*/
[[LHRNManager shareManager] prepareBridge];
LMRegionModel parameter description
| Field | Description | Source |
|---|---|---|
| appId | App ID issued by the open platform | Open platform |
| appKey | AppKey matching the AppId | Open platform |
| supportDeviceArea | Device pairing region | Open platform |
| serverCode | Server region code | Open platform |
| countryCode | Country code | Open platform |
| server | Aqara service domain | Open platform |
| coapServer | Device access server address | Open platform |
| staticsResPrefix | Static resource path | Open platform |
| appImgPrefix | CDN image path prefix | Open platform |
Other initialization parameters
| Field | Description | Source |
|---|---|---|
| h5UrlPrefix | H5 resource path within the SDK | Open platform |
| userId | User ID | Open platform |
| token | User access token | Open platform |
| language | SDK language | See table above |
The legacy APIs
[LMOpenSDK setServer:appId:appKey:iconBaseUrl:],setCoapServer:, andsetCountryCode:are deprecated. Please usesetRegionModel:for initialization.
3.2 Jump door lock into the network
Where needed, import the header file of LMRnFramework, click to jump to the header file, you can view the corresponding interface description.
#import <LMRnFramework/LMBusiRnSDK.h>
API - Jump door lock network plug-in
/**
@param deviceModel Device model
@param positionId Position id
@param navC Navigation controller, get the topmost controller by default
*/
- (void)startRnAccessPage: (NSString *)deviceModel
positionId:(NSString *)positionId
navC: (UINavigationController * _Nullable)navC;
Parameter Description
| Field | Type of data | Describe | Access channel |
|---|---|---|---|
| deviceModel | String | Device model value | See appendix list of supported door lock devices |
| positionId | String | Room location | Interface acquisition, see Aqara Developer Platform |
Example:
[[LMBusiRnSDK shareManager] startRnAccessPage: @"aqara.lock.agl002" positionId:@"real1.xxxxxxxxxxxxxxxxxxx512" navC:nil];
3.3 Jump door lock control plugin
Where needed, import the header file of LMRnFramework, click to jump to the header file, you can view the corresponding interface description.
#import <LMRnFramework/LMBusiRnSDK.h>
API - Jump door lock control plugin
/**
@param deviceId Device id
@param deviceModel Device model
@param navC Navigation controller, get the topmost controller by default
*/
- (void)startRnDevicePage:(NSString *)deviceId
deviceModel: (NSString *)deviceModel
navC: (UINavigationController * _Nullable)navC;
| Field | Type of data | Describe | Access channel |
|---|---|---|---|
| deviceModel | String | Device model value | See appendix list of supported door lock devices |
| deviceId | String | Device Id | After the device is configured successfully, the device id will be generated |
Example:
[[LMBusiRnSDK shareManager] startRnDevicePage:@"lumi.54efxxxxxxxxxxxxxc88b" deviceModel:@"aqara.lock.agl002" navC:nil];
3.4 Plugin News Subscription
API - Register Rn plugin message listener
/// @param callback Message listener callback
/// @note message NSDictionary, Structure: { action: 'action_xxx_xxx', param: {... ... } }
/// --action:
/// action_access_success The door lock is connected to the network successfully
/// action_add_gateway Add hub
/// action_open_ifttt Turn on automation
/// action_open_scene Open scene
- (void)registerRnPluginMessageNotification:(void(^_Nullable)(NSDictionary * _Nullable message))callback;
| Field | Type of data | Describe | Access channel |
|---|---|---|---|
| callback | Block | Message listener callback | None |
| message | NSDictionary | Message body | None |
note: According to the needs of your project, subscribe and parse related actions, and handle message events by yourself.
Example:
[[LMBusiRnSDK shareManager] registerRnPluginMessageNotification:^(NSDictionary * _Nullable message) {
NSLog(@"messsge: %@", message);
if (message && [message objectForKey: @"action_access_success"]) {
NSDictionary *param = [message objectForKey: @"param"];
/// TODO: Handle prompts for successful network access, device name modification, etc.
NSLog(@"--- The door lock is connected to the network successfully ---");
}
}];
API - Remove the Rn plugin message listener
- (void)unregisterRnPluginMessageNotification;
| Field | Type of data | Describe | Access channel |
|---|---|---|---|
| None | None | None | None |
note: According to the needs of your project, if the plug-in message listener has been registered, please remove it in an appropriate place such as dealloc to avoid memory leaks.
Example:
[[LMBusiRnSDK shareManager] unregisterRnPluginMessageNotification];