IOS OpenSDK Docking Document - Imou Open Platform
IOS OpenSDK docking document
iOS LCOpenSDK, as a complete set of client access frameworks connected to Imou Cloud, allows developers to quickly integrate Imou Cloud video capabilities in their own iOS applications. This OpenSDK only includes the function of debugging on the real machine, and does not support any simulator debugging. , Support Xcode 9.0 and above.
1. OpenSDK installation
There are two ways to install OpenSDK: install via cocoapods and install manually by downloading the compressed package from the official website
1.1 CocoaPods installation
1.1.1 Introduction of CocoaPods
Add pod'LCOpenSDK' statement in Podfile
Execute pod install
Note: If it cannot be imported, the local warehouse may need to be updated, and pod repo update needs to be executed.
After the installation is successful, the following figure:

1.1.2 Path configuration
- Framework path: Build Setting->Search Paths->Framework Search Paths add:
$(PROJECT_DIR)/Pods/LCOpenSDK/Framework
- Header file path: Build Setting->Search Paths->Header Search PathsAdd:
$(PROJECT_DIR)/Pods/LCOpenSDK/Framework/LCOpenSDKDynamic.framework/Headers/LCOpenSDK
$(PROJECT_DIR)/Pods/LCOpenSDK/Framework/LCOpenSDKDynamic.framework/Headers/LCOpenNetSDK
- Build Settings->Build Options ->Enable Bitcode set to NO
1.2 Compressed package installation
Download the IOS version of the OpenSDK compressed package from the official website of Imou Cloud Open Platform and manually import it locally. At this time, pay attention to the SDK path when importing. Take the demo as an example. OpenSDK is located under the Depend folder in the project directory.

1.2.1 Path configuration
- Framework path: Build Setting->Search Paths->Framework Search Paths add:
$(PROJECT_DIR)/Depend
- Header file path: Build Setting->Search Paths->Framework Search PathsAdd:
$(PROJECT_DIR)/Depend/LCOpenSDKDynamic.framework/Headers
$(PROJECT_DIR)/Depend/LCOpenSDKDynamic.framework/Headers/LCOpenSDK
$(PROJECT_DIR)/Depend/LCOpenSDKDynamic.framework/Headers/LCOpenNetSDK
- Path: Build Phases->Embed Frameworks add:
LCOpenSDKDynamic.framework, Destinations select Frameworks.
Remarks: Note: $(PROJECT_DIR) is the directory where the Demo project is located, add LCOpenSDKDemo and Depend folders as required (corresponding to iOS_demo and iOS_sdk folders); if the Build Phases -> Embed Frameworks path does not exist, select the plus sign in the upper left corner, and then select NEW Copy Files Phase to add, and finally double-click to modify the name to Embed Frameworks.
1.2.2 System library configuration
Add the following system libraries under the project TARGETS->Build Phases->Link Binary With Libraries:
CoreAudio.framework
MediaPlayer.framework
AudioToolbox.framework
VideoToolbox.framework
OpenGLES.framework
MediaAccessibility.framework
CoreVideo.framework
AVFoundation.framework
CoreMedia .framework
libz.tbd (libz.dylib)
After configuration, as shown below:

1.3 Permission configuration
The OpenSDK needs to be configured with relevant system permissions, mainly including the following:
Album:NSPhotoLibraryUsageDescription
Photo Storage:NSPhotoLibraryAddUsageDescription
Microphone:NSMicrophoneUsageDescription
Camera:NSCameraUsageDescription
Local Network:NSLocalNetworkUsageDescription
Geographical:NSLocationUsageDescription
Note:The device distribution network also needs multicast permission, which needs to be applied from Apple Developer Center.
2. Initialization
2.1 Init OpenSDK
Before using the opensdk, we need to initialize the opensdk. The initialization operation mainly depends on our open lcopensdk_ API class.
Refer to the following for specific code implementation:
/** init */
LCOpenSDK_ApiParam * apiParam = [[LCOpenSDK_ApiParam alloc] init];
/** 1. set https */
apiParam.procotol = PROCOTOL_TYPE_HTTPS;
/** 2. set Imou Cloud Host */
apiParam.addr = @"openapi-[Data Center].easy4ip.com";
/** 3. set port */
apiParam.port = 443;
/** 4. set developer access token */
apiParam.token = @"********";
/** 5. init opensdk */
LCOpenSDK_Api* m_hc = [[LCOpenSDK_Api shareMyInstance] initOpenApi:apiParam];
Note: Obtain an access token before init: Administrator accessToken or Sub-account accessToken. Replace
[Data Center]inaddrwith your data-center id.
2.2 Configure opensdk log level
Opensdk provides the log printing class_ Log, developers can choose to configure the appropriate log level. The default level is LogLevelTypeFatal.
// init LCOpenSDK_LogInfo instance
LCOpenSDK_LogInfo *info = [LCOpenSDK_LogInfo new];
// set log level
info.levelType = LogLevelTypeDebug;
[[LCOpenSDK_Log shareInstance] setLogInfo:info];
LogLevelType:
LogLevelTypeFatal = 1,// Major error
LogLevelTypeError,// Error
LogLevelTypeWarning,// Warn
LogLevelTypeInfo,// Info
LogLevelTypeDebug// Debug
Note:you can adjust the SDK log level to complete problem reproduction and log capture, which is convenient for subsequent problem location and analysis.
3. Device add function
Wireless distribution network is one of the basic functions of OpenSDK. It can be used in combination with wireless distribution network as well as device search and device initialization. Currently OpenSDK supports SmartConfig and soft AP network configuration methods. Different settings support network configuration methods. Different, the specific network distribution method to be used needs to be determined according to the device model.
3.1 SmartConfig distribution network addition
Developers can obtain information such as device S/N by scanning the label at the bottom of the device or manually entering it.
Call unBindDeviceInfo to query supported provisioning modes and bind state.
Check whether the device is binding.
Judge whether the network mode supported by the current device is SmartConfig.
Start the wireless network and search the device initialization information in the LAN.
Stop the network after searching the device and stop searching the device.
Initialize the device.
Call deviceOnline (or equivalent) to confirm the device is online.
When online, call bindDevice to complete binding.
The specific code implementation of the above three steps is as follows:
/** 1. Initialize the LCOpenSDK_ConfigWIfi object */
LCOpenSDK_ConfigWIfi *m_configWifi = [[LCOpenSDK_ConfigWIfi alloc] init];
/**
2. Start distribution network
devId: device serial number
ssid: wifi name
password: wifi password
security: Security code, required for SC code equipment, non-SC equipment transmits @""
*/
NSInteger iRet = [m_configWifi configWifiStart:@"********"
ssid:@"********"
password:@"********"
secure:@"********"
voiceFreq:11000];
if (iRet <0) {
NSLog(@"smartconfig failed\n");
}
__block NSString *theMac = nil; /** device mac address */
__block NSString *theIp = nil; /** Device ip */
__block int thePort = 0; /** Device port */
__block int theInitStatus = 0; /** Device initialization information, 0: no need to initialize, 1: need to be initialized and not initialized 2: need to be initialized and initialized */
/** 3. Initialize device initialization information */
LCOpenSDK_DeviceInit *deviceInit = [[LCOpenSDK_DeviceInit alloc] init];
/** 4. Search device initialization information */
[deviceInit searchDeviceInitInfo:@"********" timeOut:60000*2 success:^(LCOPENSDK_DEVICE_INIT_INFO info) {
theMac = [NSString stringWithUTF8String:info.mac];
theIp = [NSString stringWithUTF8String:info.ip];
thePort = info.port;
theInitStatus = info.status;
}];
if (!theMac || !theIp) {
NSLog(@"Search device init info failed!\n");
}
/** 5. Stop network distribution */
[m_configWifi configWifiStop];
/** 6. The initialization status is 1 and it is not a SC code device, to initialize, the initialization password can be set by yourself */
int ret = [deviceInit initDevice:theMac password:@"********" ip:theIp];
if (-2 == ret) {
NSLog(@"Init device failed!\n");
}
3.2 SoftAP distribution network addition
Developers can obtain information such as device S/N by scanning the label at the bottom of the device or manually entering it.
Call unBindDeviceInfo to query supported provisioning modes and bind state.
Check whether the device is binding.
Judge whether the network mode supported by the current device is SoftAP.
Connect device hotspot
LAN searches for device initialization information: if the device information is searched, start the distribution network process
Start SoftAP distribution network
Call deviceOnline (or equivalent) to confirm the device is online.
When online, call bindDevice to complete binding.
The code is implemented as follows:
/** 1. Initialize the device initialization object */
LCOpenSDK_SearchDevices *m_deviceInit = [[LCOpenSDK_SearchDevices alloc] init];
/** 2. Search device initialization information information */
__block int m_initDevStatus = 0;
[m_deviceInit startSearchDevices:@"********" timeOut:10*1000 success:^(LCOPENSDK_DEVICE_INIT_INFO info) {
m_initDevStatus = info.status;
}];
/** 3. Initialize the soft Ap distribution network object */
LCOpenSDK_SoftAPConfig *m_softAP = [[LCOpenSDK_SoftAPConfig alloc] init];
/** 4. The initialization status m_initDevStatus is 0 or the SC code device, directly configure the network with soft Ap, the device password is transmitted @"admin"; the initialization status m_initDevStatus is 1, the device password is customized; SC code devices need to wear the device security code, isSC is set to YES */
NSInteger softAPResult = [m_softAP
startSoftAPConfig:@"********" wifiPwd:@"********" wifiEncry:0 netcardName:@"********" deviceIp:@"********" devicePwd:@"********" isSC:True timeout:0 handler:^(NSInteger result) {
handler(result);
}];
if (softAPResult <0) {
NSLog(@"SoftAP failed!\n");
}
4. Real-time preview
The main steps of real-time preview are:
Obtain device information through the [Device Query] (/book/05-api/03.device/summary.html) interface of the Lecheng Cloud Platform.
Call the OpenSDK interface to initialize the playback window and monitor settings.
The specific code implementation refers to the following:
/** 1. Initialize the playback window information, including position, size and index */
LCOpenSDK_PlayRealWindow *m_play = [[LCOpenSDK_PlayRealWindow alloc] initPlayWindow:CGRectMake(0, 0, 400, 300) Index:0];
/** 2. Set the background color of the playback window */
[m_play setSurfaceBGColor:[UIColor blackColor]];
/** 3. Add the play window to the parent view */
[self.view addSubview:[m_play getWindowView]];
/** 4. Set the listener object, you can listen to the playback result callback */
[m_play setPlayRealListener:(id<LCOpenSDK_PlayRealListener>)listener];
*Call the OpenSDK interface to set the playback parameters, and then start playing.
The specific code implementation refers to the following:
/** 1. Initialize the real-time preview playback parameter object */
LCOpenSDK_ParamReal *paramReal = [[LCOpenSDK_ParamReal alloc] init];
/** 2. Set the token, and the token will be obtained by calling the Lecheng Cloud Open Platform according to AppId and AppSecret */
paramReal.accessToken = @"********";
/** 3. Set the device serial number */
paramReal.deviceID = @"********";
/** 4. Set the device channel, 0 for single-channel devices, and specific channel number for multi-channel devices such as NVR */
paramReal.channel = 0;
/** 5. Set stream mode, support main stream and sub stream */
paramReal.defiMode = DEFINITION_MODE_HG;
/** 6. Set the key. If the user-defined key is a specific key, the non-user-defined key can be the device serial number*/
paramReal.psk = @"********";
/** 7. Set the playback key, it is not necessary to transmit, if it is transmitted, the streaming speed will be increased */
paramReal.playToken = @"********";
/** 8. Whether to optimize the flow, YES will increase the speed of the flow, it is recommended to pass YES */
paramReal.isOpt = YES;
/** 8. Start playing */
[m_play playRtspReal:paramReal];
- Implement monitoring callbacks.
Pseudocode: Callback bodies below are omitted; implement per your app.
The specific code implementation refers to the following:
/** 1. The playback result is called back, which can be processed differently according to the error code */
-(void)onPlayerResult:(NSString*)code Type:(NSInteger)type Index:(NSInteger)index {
// Pseudocode: implement callback body
}
/** 2. Playback start callback */
-(void)onPlayBegan:(NSInteger)index {
// Pseudocode: implement callback body
}
5. Video playback
Video playback is a function to play the video stored on the SD card and hard disk or cloud storage of the device. For device video and cloud storage video, OpenSDK provides different interfaces. Please pay attention when using it.
For the local video playback of the device, OpenSDK provides two interfaces, namely playback by file name and playback by time. The process of use can be used according to the needs of different scenarios. It is recommended to use playback by file name.
The main steps of real-time preview are:
Obtain device information through the Device Query interface of the Lecheng Cloud Platform.
Obtain cloud storage recording information through the Cloud Recording Query interface of the Lecheng Cloud Platform, Local Recording Query Get the local recording information of the device.
Call the OpenSDK interface to initialize the playback window and monitor settings.
The specific code implementation refers to the following:
/** 1. Initialize the playback window information, including position, size and index */
LCOpenSDK_PlayWindow *m_play = [[LCOpenSDK_PlayWindow alloc] initPlayWindow:CGRectMake(0, 0, 400, 300) Index:0];
/** 2. Set the background color of the playback window */
[m_play setSurfaceBGColor:[UIColor blackColor]];
/** 3. Add the play window to the parent view */
[self.view addSubview:[m_play getWindowView]];
/** 4. Set the listener object, you can listen to the playback result callback */
[m_play setWindowListener:(id<LCOpenSDK_EventListener>)self];
- Call the OpenSDK interface to set the playback parameters, and then start playing.
The specific code implementation refers to the following:
- The equipment video is played according to the file name:
/** 1. Initialize the playback parameter object by file name */
LCOpenSDK_ParamDeviceRecordFileName * paramDeviceRecord = [[LCOpenSDK_ParamDeviceRecordFileName alloc] init];
/** 2. Set the token, and the token will be obtained by calling the Lecheng Cloud Open Platform according to AppId and AppSecret */
paramDeviceRecord.accessToken = @"********";
/** 3. Set the device serial number */
paramDeviceRecord.deviceID = @"********";
/** 4. Set the device channel, 0 for single-channel devices, and specific channel number for multi-channel devices such as NVR */
paramDeviceRecord.channel = 0;
/** 5. Set the key, if the user-defined key is a specific key, the non-user-defined key can be the device serial number */
paramDeviceRecord.psk = @"********";
/** 6. Set the video name, namely, the video ID (recordId)*/
paramDeviceRecord.fileName = @"********";
/** 7. Set the playback offset time in seconds, and set it to 0 from the start of file playback*/
paramDeviceRecord.offsetTime = 0 ;
/** 8. product ID */
paramDeviceRecord.productId= @"********";
/** 9. Select the streaming type to play by file*/
paramDeviceRecord.playMode = @"********";
/** 10. Whether to play the suggestion and send it to YES*/
paramDeviceRecord.isPlayBack = YES;
/** 11. Whether to optimize the flow, YES will increase the speed of the flow, it is recommended to pass YES*/
paramDeviceRecord.isOpt = YES;
/** 12. start playing*/
[m_play playRecordStream:paramDeviceRecord];
- Equipment video is played by time:
/** 1. Initialize the playback parameter object by time */
LCOpenSDK_ParamDeviceRecordUTCTime *paramDeviceRecordUTCTime = [[LCOpenSDK_ParamDeviceRecordUTCTime alloc] init];
/** 2. Set the token, and the token will be obtained by calling the Lecheng Cloud Open Platform according to AppId and AppSecret */
paramDeviceRecordUTCTime.accessToken = @"********";
/** 3. Set the device serial number */
paramDeviceRecordUTCTime.deviceID = @"********";
/** 4. Set the device channel, 0 for single-channel devices, and specific channel number for multi-channel devices such as NVR */
paramDeviceRecordUTCTime.channel = 0;
/** 5. Set stream mode, support main stream and sub stream */
paramDeviceRecordUTCTime.defiMode = DEFINITION_MODE_HG;
/** 6. Set the key. If the user-defined key is a specific key, the non-user-defined key can be the device serial number */
paramDeviceRecordUTCTime.psk = @"********";
/** 7. The start time of recording, not 0 */
paramDeviceRecordUTCTime.beginTime = 0;
/** 8. End time of recording, not 0 */
paramDeviceRecordUTCTime.endTime = 0;
/** 9. Whether to optimize the flow, YES will increase the speed of the flow, it is recommended to pass YES */
paramDeviceRecordUTCTime.isOpt = YES;
/** 10. Whether to play the suggestion and send it to YES*/
paramDeviceRecordUTCTime.isPlayBack = YES;
/** 11. Select the streaming type to play by time*/
paramDeviceRecordUTCTime.PlayMode = @"********";
/** 12. start playing*/
[m_play playRecordStream: paramDeviceRecordUTCTime];
- Cloud storage video playback:
/** 1. Initialize cloud storage video playback parameter object */
LCOpenSDK_ParamCloudRecord *paramCloudRecord = [[LCOpenSDK_ParamCloudRecord alloc] init];
/** 2. Set the token, and the token will be obtained by calling the Lecheng Cloud Open Platform according to AppId and AppSecret */
paramCloudRecord.accessToken = @"********";
/** 3. Set the device serial number */
paramCloudRecord.deviceID = @"********";
/** 4. Set the device channel, 0 for single-channel devices, and specific channel number for multi-channel devices such as NVR */
paramCloudRecord.channel = 0;
/** 5. Set the key, if the user-defined key is a specific key, the non-user-defined key can be the device serial number */
paramCloudRecord.psk = @"********";
/** 6. Set the record Id (recordRegionID)*/
paramCloudRecord.recordRegionID = @"********";
/** 7. Set the playback offset time, the unit is second, you can set it to 0 from the beginning of the file playback */
paramCloudRecord.offsetTime = 0;
/** 8. Set the recording type, set to RECORD_TYPE_ALL */
paramCloudRecord.recordType = RECORD_TYPE_ALL;
/** 9. Set the playback timeout time, in seconds*/
paramCloudRecord.timeOut = 60;
/** 10. Whether to optimize the flow, YES will increase the speed of the flow, it is recommended to pass YES */
paramCloudRecord.isOpt = @"********";
/** 11. Play again after the TCM verifies the password */
paramCloudRecord.isReplay = @"********";
/** 12. product ID */
paramCloudRecord.productID = @"********";
/** 13. Set streaming mode */
paramCloudRecord.streamType = @"********";
/** 14. Set Record Area ID */
paramCloudRecord.recordregionID = @"********";
/** 15. Start playing */
[m_play playRecordStream:paramCloudRecord]
- Implement monitoring callbacks.
The specific code implementation refers to the following:
/** 1. The playback result is called back, which can be processed differently according to the error code */
-(void)onPlayerResult:(NSString*)code Type:(NSInteger)type Index:(NSInteger)index {
// Pseudocode: implement callback body
}
/** 2. Playback start callback */
-(void)onPlayBegan:(NSInteger)index {
// Pseudocode: implement callback body
}
/** 3. Playback complete callback */
-(void)onPlayFinished:(NSInteger)index {
// Pseudocode: implement callback body
}
/** 4. File start time and end time callback */
-(void)onFileTime:(long)beginTime EndTime:(long)endTime Index:(NSInteger)index {
// Pseudocode: implement callback body
}
/** 5. File playback time callback */
-(void)onPlayerTime:(long)time Index:(NSInteger)index {
// Pseudocode: implement callback body
}
6. Voice intercom
Voice intercom is the function of voice intercom between the device and the client. While the device is previewing in real time, the voice intercom is performed.
The development of voice intercom function is mainly divided into the following steps:
Develop real-time preview function.
Call the OpenSDK interface to initialize the voice intercom object, initialize the playback parameter object and set the parameters to start the intercom.
The specific code implementation refers to the following:
/** 1. Initialize the voice intercom object */
LCOpenSDK_AudioTalk *m_talker = [[LCOpenSDK_AudioTalk alloc] init];
/** 2. Set the monitoring object */
[m_talker setListener:(id<LCOpenSDK_TalkerListener>)self];
/** 3. Initialize the voice intercom parameter object */
LCOpenSDK_ParamTalk *paramTalk = [[LCOpenSDK_ParamTalk alloc] init];
/** 4. Set the token, and the token will be obtained by calling the Lecheng Cloud Open Platform according to AppId and AppSecret */
paramTalk.accessToken = @"********";
/** 5. Set the device serial number */
paramTalk.deviceID = @"********";
/** 6. Set the device channel, -1 is the device intercom, and the channel intercom is the specific channel number */
paramTalk.channel = -1;
/** 7. Set the key. If the user-defined key is a specific key, the non-user-defined key can be the device serial number */
paramTalk.psk = @"********";
/** 8. Set the playback key, it is not necessary to transmit, if it is transmitted, the streaming speed will be increased */
paramTalk.playToken = @"********";
/** 9. Whether to optimize the flow, YES will increase the speed of the flow, it is recommended to pass YES */
paramTalk.isOpt = YES;
/** 10. Start intercom */
[m_talker playTalk:paramTalk];
- Realize the intercom result callback.
The specific code implementation refers to the following:
/** Intercom result callback */
-(void) onTalkResult:(NSString *) error TYPE:(NSInteger) type {
// Pseudocode: implement callback body
}
7. Video Download
OpenSDK provides an interface for developers to develop the download function of device video and cloud storage video. At present, the interface only provides video file download in MP4 format, and other formats are not currently supported.
The development of voice intercom function is mainly divided into the following steps:
Obtain device information through the Device Query interface of the Lecheng Cloud Platform.
Obtain cloud storage recording information through the Cloud Recording Query interface of the Lecheng Cloud Platform, Local Recording Query Get the local recording information of the device.
Call the OpenSDK interface to initialize the download object, set the monitor object, and download the video.
The specific code implementation refers to the following:
/** 1. Path name */
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString* libraryDirectory = [paths objectAtIndex:0];
NSString* myDirectory = [libraryDirectory stringByAppendingPathComponent:@"lechange"];
NSString* downloadDirectory = [myDirectory stringByAppendingPathComponent:@"download"];
/** Don’t make everything the same, or it will overwrite */
NSString* infoPath = [downloadDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"record_download"]];
NSString* m_downloadPath = [infoPath stringByAppendingString:@".mp4"];
/** 2. Create a path based on the path name */
NSFileManager* fileManage = [NSFileManager defaultManager];
NSError* pErr;
BOOL isDir;
if (NO == [fileManage fileExistsAtPath:myDirectory isDirectory:&isDir]) {
[fileManage createDirectoryAtPath:myDirectory withIntermediateDirectories:YES attributes:nil error:&pErr];
}
if (NO == [fileManage fileExistsAtPath:downloadDirectory isDirectory:&isDir]) {
[fileManage createDirectoryAtPath:downloadDirectory withIntermediateDirectories:YES attributes:nil error:&pErr];
}
/** 3. Create download object */
LCOpenSDK_Download* m_download = [LCOpenSDK_Download shareMyInstance];
/** 4. Set up monitor */
[m_download setListener:(id<LCOpenSDK_DownloadListener>)self];
/** 5. Start cloud video download */
[m_download startDownload:0 filepath:m_downloadPath token:@"********" devID:@"********" channelID:0 psk:@"********" recordRegionId:@"********" Type:1000 Timeout:10];
/** 5. Start device video download, speed download speed is set to 16 times speed, fileID level recordId */
[m_download startDownload:0 filepath:m_downloadPath token:@"********" devID:@"********" decryptKey:@"********" fileID:@"********" speed:16];
*Implement download callback.
Pseudocode: Download callback bodies below are omitted.
The specific code implementation refers to the following:
/** 1. Download data callback */
-(void) onDownloadReceiveData:(NSInteger)index datalen:(NSInteger)datalen {
// Pseudocode: implement callback body
}
/** 2. Download status callback */
-(void) onDownloadState:(NSInteger)index code:(NSString *)code type:(NSInteger)type {
// Pseudocode: implement callback body
}
8. Data Decryption
At present, the device alarm thumbnail and video cover image are encrypted and stored by default. They can be displayed normally only after decryption: use LCOpenSDK_Utils method to decrypt the encrypted picture data.
The specific code implementation refers to the following:
NSData* dataOut = [[NSData alloc] init];
NSInteger iret = [[LCOpenSDK_Utils new] decryptPic:picData deviceID:deviceId key:key bufOut:&dataOut];
NSLog(@"decrypt iret[%ld]", (long)iret);
if (0 == iret) {
UIImage* img = [UIImage imageWithData:[NSData dataWithBytes:[dataOut bytes] length:[dataOut length]]];
[cache storeImage:img forKey:key_temp toDisk:YES completion:^{
}];
[self setImage:img];
}
