环境搭建

一、概述

本文主要介绍在集成绿米SDK前,需要在您的项目中添加的一些配置,以及获取SDK初始化必要的参数

二、前提条件

  1. 确保您已经完成准备工作

三、添加依赖

3.1 编译环境需求

支持版本

系统 版本号
iOS 13.0
iPad OS 13.0

Swift版本 5.0+

3.2 权限声明

3.2.1 SDK需要在Xcode中添加以下隐私权限:

权限 Info.plist Key
Bluetooth Privacy - Bluetooth Always Usage Description NSBluetoothAlwaysUsageDescription
Camera Privacy - Camera Usage Description NSCameraUsageDescription
Microphone Privacy - Microphone Usage Description NSMicrophoneUsageDescription
Photo Library Privacy - Photo Library Usage Description NSPhotoLibraryUsageDescription
Location Privacy - Location When In Use Usage Description NSLocationWhenInUseUsageDescription
Location Privacy - Location Always and When In Use Usage Description NSLocationAlwaysAndWhenInUseUsageDescription
Local Network Privacy - Local Network Usage Description NSLocalNetworkUsageDescription
HomeKit Privacy - HomeKit Usage Description NSHomeKitUsageDescription

3.2.2 配网SDK额外需要在Xcode中添加以下能力:

权限 Entitlements Key
Hotspot com.apple.developer.networking.HotspotConfiguration
Access WiFi Information com.apple.developer.networking.wifi-info
Wireless Accessory Configuration com.apple.external-accessory.wireless-configuration

3.2.3 当入网设备是Matter协议时,Xcode需要添加 Matter Extension Target

iOS_CreateMatterExtensionTarget

3.2.4 宿主App还需要在Xcode中申请以下能力:

iOS_Host_App_Capabilities

权限 Entitlements Key
HomeKit AllowSetUpPayload com.apple.developer.homekit.allow-setup-payload
Matter Allow Setup Payload ccom.apple.developer.matter.allow-setup-payload
Manager Thread Network Credentials com.apple.developer.networking.manage-thread-network-credentials
App Groups com.apple.security.application-groups

3.2.5 Matter Extension还需要在Xcode中申请以下能力:

iOS_Matter_Extension_Capabilities

权限 Entitlements Key
App Groups com.apple.security.application-groups

3.2.6 同时需要在宿主App的Info.plist 中添加以下键值对:

iOS_Host_App_Bonjure_Service

Key Values
NSBonjourServices _meshcop._udp
_matter._tcp
_matterc._udp
_matterd._udp
_aqara._tcp.

3.2.3.4 在Matter Extension的Info.plist 中添加以下键值对:

iOS_Matter_Extension_Bonjure_Service

Key Values
NSBonjourServices _matter._tcp
_matterc._udp
_matterd._udp

重要

Manager Thread Network Credentials 能力需要单独在开发者网站申请: https://developer.apple.com/contact/request/threadnetwork 上述隐私权限说明必须要有,否则首次使用相应权限时应用程序会闪退

四、集成

4.1 安装 CocoaPods

我们推荐使用Homebrew来安装CocoaPods

4.1.1 Podfile 集成

platform :ios, '13.0'
inhibit_all_warnings!
use_modular_headers!

target 'CameraOpenSDKDemo' do

  # 基础SDK,配网、设备控制、Camera 相关功能都需要集成基础SDK
  pod 'LMBaseEncryption', :path => './CameraOpenSDKDemo/AqaraFrameworks/LMBaseEncryption'
  pod 'LMFramework', :path => './CameraOpenSDKDemo/AqaraFrameworks/LMFramework'
  pod 'LMSwiftCore', :path => './CameraOpenSDKDemo/AqaraFrameworks/LMSwiftCore'

  # UI组件库
  pod 'LMCommonUI', :path => './CameraOpenSDKDemo/AqaraFrameworks/LMCommonUI'
  pod 'LMCommonUISwift', :path => './CameraOpenSDKDemo/AqaraFrameworks/LMCommonUISwift'

  # 配网SDK,需要集成 UI 组件库
  pod 'LMExtensionNetwork', :path => './CameraOpenSDKDemo/AqaraFrameworks/LMExtensionNetwork'
  pod 'LMMatter', :path => './CameraOpenSDKDemo/AqaraFrameworks/LMMatter'
  pod 'LMMatterCore', :path => './CameraOpenSDKDemo/AqaraFrameworks/LMMatterCore'
  pod 'LMMatterUI', :path => './CameraOpenSDKDemo/AqaraFrameworks/LMMatterUI'
  pod 'LMAccessNetSDK', :path => './CameraOpenSDKDemo/AqaraFrameworks/LMAccessNetSDK'

  # 设备控制SDK,需要集成 UI 组件库
  pod 'LMFirmwareUpgradeFramework', :path => './CameraOpenSDKDemo/AqaraFrameworks/LMFirmwareUpgradeFramework'
  pod 'LMMeshDriverFramework', :path => './CameraOpenSDKDemo/AqaraFrameworks/LMMeshDriverFramework'
  pod 'LMMeshDriver_UI', :path => './CameraOpenSDKDemo/AqaraFrameworks/LMMeshDriver_UI'

  # Camera SDK,需要集成 UI 组件库
  pod 'LMCameraFramework', :path => './CameraOpenSDKDemo/AqaraFrameworks/LMCameraFramework'
  pod 'EMPageViewController', :git => 'https://github.com/MrLittleWhite/EMPageViewController.git', :tag => '4.0.8'

  # 上述SDK中部分依赖库需指定 git 地址或提交哈希值
  pod 'RealReachability', :git => 'https://github.com/OHeroJ/RealReachability.git'
  pod 'SGQRCode', :git=>'https://github.com/acodeworker/SGQRCode.git', :commit => 'a3054dd68f94e46902a82291b897f50a31ed836a'

end

# 当入网设备是Matter协议时,Matter Extension 集成SDK
target 'MatterExtension' do
  pod 'LMMatter', :path => './CameraOpenSDKDemo/AqaraFrameworks/LMMatter'
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      # 临时禁用 ActiveLabel 的并发安全检查
      if target.name == 'ActiveLabel'
        config.build_settings['SWIFT_STRICT_CONCURRENCY'] = 'minimal'
      end
    end
  end
end

五、初始化

5.1 获取SDK初始化必要的参数

5.1.1 AppId、AppKey获取

参见文档准备工作

5.1.2 其他必要参数获取

根据不同的账户授权方式,获取方式也不一致,详情请参考授权管理

通常来讲,大部份时候都是使用虚拟账户授权模式,即第三方App需要请求自身云平台获取相关的参数:

5.2 SDK初始化

集成绿米iOS端各个业务SDK,通常情况下仅需通过LMOpenSDK进行统一初始化即可,其他业务SDK通常情况下不需要单独进行初始化。

5.2.1 进行统一初始化

初始化接口调用

/**
     中文:
     appId:             从开放平台申请的APPID
     appKey:            与APPID配套的APPKey
     supportDeviceArea:
     serverCode:        服务器地区(见开放平台)serverCode
     countryCode:       服务器地区(见开放平台)serverCode
     server:            Aqara配网域名(见开放平台)
     coapServer:        配置设备的服务器地址以及服务器区域码
     appImgPrefix:      配网UI层部分CDN图片的路径
     staticsResPrefix:  静态资源路径

     English:
     appId:             APPID applied from open platform
     appKey:            The APPKey that matches the APPID
     supportDeviceArea:
     serverCode:        Aqara Server Code
     countryCode:       Aqara Server Code
     server:            Aqara distribution network domain name
     coapServer:        Configure the server address and server area code of the device
     appImgPrefix:      Path of CDN images in the UI
     staticsResPrefix:  Path of Static Resource
     */

    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" stringByAppendingString:@"/default"];
    [LMOpenSDK setRegionModel:regionModel];

    /**
     设置SDK内H5资源路径
     Set H5 resource path within SDK
     */
    [LMOpenSDK setH5UrlPrefix:@"Your H5UrlPrefix"];

    /**
     setLanguage:
     "en"           英           English
     "ru"           俄           Russia
     "ko"           韩           Korea
     "zh-Hans"      中           China
     "zh-HK"        中国香港      Hong Kong, China
     "zh-Hant-TW"   中国台湾      Taiwan, China
     */
    [LMOpenSDK setLanguage:@"Your Language"];

    /**
     配置从开放平台申请到的用户信息
     Configure useid token obtained from open platform applications
     */
    [LMOpenSDK setUserId:@"Your UserId" token:@"Your AccessToken"];

    /**
     如果你的应用中没有使用设备控制、设备设置等功能(即没有使用 LMMeshDriverFramework库),下面的配置可以忽略
     以下配置的功能是:SDK将读取本地插件
     本地文件路径:localjs
     The function of the following configuration is: the SDK will read the local plug-in
     local file path: localjs
     */
    [LMDriverConfig sharedInstance].isLocalResource(YES);
/**
     中文:
     appId:             从开放平台申请的APPID
     appKey:            与APPID配套的APPKey
     supportDeviceArea:
     serverCode:        服务器地区(见开放平台)serverCode
     countryCode:       服务器地区(见开放平台)serverCode
     server:            Aqara配网域名(见开放平台)
     coapServer:        设备接入服务器
     appImgPrefix:      配网UI层部分CDN图片的路径
     staticsResPrefix:  静态资源路径

     English:
     appId:             APPID applied from open platform
     appKey:            The APPKey that matches the APPID
     supportDeviceArea:
     serverCode:        Aqara Server Code
     countryCode:       Aqara Server Code
     server:            Aqara distribution network domain name
     coapServer:        Configure the server address of the device
     appImgPrefix:      Path of CDN images in the UI
     staticsResPrefix:  Path of Static Resource
     */

    let regionModel = LMRegionModel<AnyObject, AnyObject>()
    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" + "/default"
    LMOpenSDK.setRegionModel(regionModel)

    /**
     设置SDK内H5资源路径
     Set H5 resource path within SDK
     */
    LMOpenSDK.setH5UrlPrefix("Your H5UrlPrefix")

    /**
     setLanguage:
     "en"           英           English
     "ru"           俄           Russia
     "ko"           韩           Korea
     "zh-Hans"      中           China
     "zh-HK"        中国香港      Hong Kong, China
     "zh-Hant-TW"   中国台湾      Taiwan, China
     */
    LMOpenSDK.setLanguage("Your Language")

    /**
     配置从开放平台申请到的用户信息
     Configure useid token obtained from open platform applications
     */
    LMOpenSDK.setUserId("Your UserId", token: "Your AccessToken")

    /**
     如果你的应用中没有使用设备控制、设备设置等功能(即没有使用 LMMeshDriverFramework库),下面的配置可以忽略
     以下配置的功能是:SDK将读取本地插件
     本地文件路径:localjs
     The function of the following configuration is: the SDK will read the local plug-in
     local file path: localjs
     */
    LMDriverConfig.sharedInstance().isLocalResource()(true)

参数说明

字段 数据类型 说明 获取渠道
appId String App唯一标识 Aqara开发者平台
appKey String App唯一标识 Aqara开发者平台
server String SDK请求的域名 接口获取,详情请查看Aqara开发者平台
h5UrlPrefix String SDK请求的H5链接 接口获取,详情请查看Aqara开发者平台
staticsResPrefix String SDK请求的图片cdn地址 接口获取,详情请查看Aqara开发者平台
userId String 用户唯一标识 接口获取,详情请查看Aqara开发者平台
accessToken String 用户访问令牌 接口获取,详情请查看Aqara开发者平台
area String App 所在地区 默认值为CN
language String App 当前语言 默认值为zh
supportDeviceArea String 设备入网的地区 默认值CHN

注意:area和supportDeviceArea,部分地区代号存在差异

language取值

language参数会影响SDK及云端返回到多语言类型

取值 描述 说明
zh 简体中文 默认值
zh_TW 台湾繁体 /
zh_HK 香港繁体 /
en 英文 /
ko 韩文 /
ru 俄文 /
de 德文 /
it 意大利文 /
fr 法文 /
es 西班牙文 /

注意:该值仅影响动态化获取信息的多语言,例如云端接口、配置文件等,SDK本身使用到的多语言(存放在strings.xml中)则跟随宿主App的多语言。

area取值

area参数会影响云端接口的业务逻辑,在某些地区下可能存在部分业务不可用。

取值 描述 说明
CN 中国大陆 默认值
HMT 中国香港、澳门、台湾 /
US 美国 /
EU 欧洲 /
RU 俄罗斯 /
SEA 东南亚 /
KR 韩国 /
JP 日本 /
AU 意大利 /
ME 中东 /
AF 非洲 /
OTHER 其他地区 /

supportDeviceArea取值

supportDeviceArea参数会影响设备入网配置。(部分设备仅能在特定地区进行激活使用)

取值 描述 说明
CHN 中国大陆 默认值
HMT 中国香港、澳门、台湾 /
USA 美国 /
EU 欧洲 /
RUS 俄罗斯 /
SEA 东南亚 /
KR 韩国 /
JP 日本 /
AU 意大利 /
ME 中东 /
AF 非洲 /
OTHER 其他地区 /
lumi LogoCopyright © 2023 深圳绿米联创科技有限公司 all right reserved,powered by Gitbook文档修改时间: 2025-11-07 11:22:15

results matching ""

    No results matching ""