GizWifiSDK 类
机智云 Wifi SDK 的基础类,为APP开发者提供设备配置和发现、用户登录和注册等功能。
目录
属性访问
[delegate]
使用委托获取对应事件。GizWifiSDK 对应的回调接口在 GizWifiSDKDelegate 定义。需要用到哪个接口,回调即可。
定义
@property (weak, nonatomic) id <GizWifiSDKDelegate>_Nullable delegate;
[deviceList]
NSArray类型,为 GizWifiDevice 对象数组。设备列表缓存,APP 访问该变量即可得到当前 GizWifiSDK 发现的设备列表。
定义
@property (strong, nonatomic, readonly) NSArray <GizWifiDevice*>* _Nullable deviceList;
API 定义
[sharedInstance]
获取 GizWifiSDK 单例的实例。
返回值返回初始化后 SDK 唯一的实例。SDK 未初始化,或者初始化失败,返回 nil。
定义
+ (instancetype)sharedInstance;
代码示例
GizWifiSDK mGizWifiSDKInstance = [GizWifiSDK sharedInstance];
[startWithAppInfo]
启动 SDK。该接口执行成功后,其他接口功能才能正常执行。该接口执行结果由回调didNotifyEvent通知App,回调参数eventID为8316表示SDK启动成功。
如果App要做域名切换和设备类型过滤,则要在此时就指定好域名cloudSeviceInfo和产品信息productInfo。
SDK启动成功后,如果App已经设置了delegate,SDK会立即通过didDiscovered上报发现的设备。
定义
+ (void)startWithAppInfo:(NSDictionary <NSString*, NSString*>* _Nonnull)appInfo productInfo:(NSArray <NSDictionary <NSString*, NSString*>*>* _Nullable)productInfo cloudServiceInfo:(NSDictionary <NSString*, NSString*>* _Nullable)cloudSeviceInfo;
参数
属性名 |
描述 |
appInfo |
应用信息,格式:{"appId": "xxx", "appSecret": "xxx"}。此参数不能填nil,appId和appSecret必须为有效值。在机智云开发者中心 dev.gizwits.com 中,每个注册的设备在对应的“应用配置”中,都能够查到对应的 appID和appSecret |
productInfo |
产品信息数组,格式:[{"productKey": "xxx", "productSecret": "xxx"}],此参数选填。如果填写了此参数,则需保证productKey和productSecret都为有效值,否则会被忽略。SDK会根据此参数过滤设备列表 |
cloudServiceInfo |
服务器域名信息,格式:{"appApi": "xxx", // String类型,api服务域名,必填 "push": "xxx" // String类型,推送服务域名,可不填}。如果使用机智云统一部署的云服务域名,此参数填nil,此时将根据用户手机的地理位置信息使用匹配的域名。如果需要独立部署,此参数必须指定域名信息。如果需要指定端口号,可指定Http端口如:xxx.gizwits.com:80,或同时指定Http和Https端口如:xxx.gizwits.com:80&443。不指定端口号时,形如:xxx.gizwits.com |
回调
当发生GizEventType中列举的事件类型时,SDK会主动触发该回调,该回调通知的主要是发生的异常事件
- (void)wifiSDK:(GizWifiSDK *)wifiSDK didNotifyEvent:(GizEventType)eventType eventSource:(id)eventSource eventID:(GizWifiErrorCode)eventID eventMessage:(NSString *)eventMessage;
回调参数
属性名 |
描述 |
wifiSDK |
回调的 GizWifiSDK 单例 |
eventType |
事件类型。指明发生了哪一类的事件,详细见 GizEventType 枚举定义 |
eventSource |
事件源,指是谁触发的事件。如果eventType是GizEventSDK,eventSource为nil;如果是GizEventDevice,eventSource需要强制转换为GizWifiDevice类型再使用;如果是GizEventM2Mservice或者GizEventToken,eventSource需要强制转换为NSString类型再使用 |
eventID |
事件ID。代表事件编号,详细见 GizWifiErrorCode 枚举定义。该参数指出 eventSource 发生了什么事 |
eventMessage |
事件ID的消息描述 |
代码示例
[GizWifiSDK sharedInstance].delegate = self;
NSDictionary* appInfo = @{@"appId": @"your_app_id", @"appSecret": @"your_app_secret"};
NSArray *productInfo = [NSArray arrayWithObjects: @{@"productKey": @"your_product_key", @"productSecret": @"your_product_secret"}, nil];
[GizWifiSDK startWithAppInfo:appInfo productInfo:productInfo cloudServiceInfo:nil];
- (void)wifiSDK:(GizWifiSDK *)wifiSDK didNotifyEvent:(GizEventType)eventType eventSource:(id)eventSource eventID:(GizWifiErrorCode)eventID eventMessage:(NSString *)eventMessage {
if(eventType == GizEventSDK) {
NSLog(@"SDK event happened: [%@] = %@", @(eventID), eventMessage);
if(result.code == GIZ_SDK_START_SUCCESS) {
}
} else if(eventType == GizEventDevice) {
GizWifiDevice* mDevice = (GizWifiDevice*)eventSource;
NSLog(@"device mac %@ disconnect caused by %@", mDevice.macAddress, eventMessage);
} else if(eventType == GizEventM2MService) {
NSLog(@"M2M domain %@ exception happened: [%@] = %@", (NSString*)eventSource, @(eventID), eventMessage);
} else if(eventType == GizEventToken) {
NSLog(@"token %@ expired: %@", (NSString*)eventSource, eventMessage);
}
}
[getVersion]
获取 SDK 版本号。
返回值返回当前 SDK 的版本号码
定义
+ (NSString *)getVersion;
代码示例
[getPhoneID]
获取 手机的唯一标志码
定义
+ (NSString* _Nullable)getPhoneID;
代码示例
[disableLAN]
设置是否禁用小循环功能
定义
+ (void)disableLAN:(BOOL)disabled
参数
回调
- (void)wifiSDK:(GizWifiSDK *)wifiSDK didDisableLAN:(NSError *)result;
回调参数
属性名 |
描述 |
wifiSDK |
回调的 GizWifiSDK 单例 |
result |
详细见 GizWifiErrorCode 枚举定义。GIZ_SDK_SUCCESS 表示成功,其他为失败 |
代码示例
[GizWifiSDK sharedInstance].delegate = self;
[GizWifiSDK disableLAN: YES];
- (void)wifiSDK:(GizWifiSDK *)wifiSDK didDisableLAN:(NSError *)result {
if(result.code == GIZ_SDK_SUCCESS) {
} else {
}
};
[setDeviceOnboardingDeploy]
设备配网接口。配网时可自动完成设备域名部署,此接口对模组固件版本向前兼容。
设备处于 softap 模式时,会产生一个热点名称,手机 wifi 连接此热点后就可以配置了。如果是机智云提供的设备wifi固件,热点名称前缀为"XPG-GAgent-",密码为"123456789"或无密码。设备处于 airlink 模式时,手机随时都可以开始配置
定义
- (void)setDeviceOnboardingDeploy:(NSString* _Nonnull)ssid key:(NSString* _Nullable)key configMode:(GizWifiConfigureMode)mode softAPSSIDPrefix:(NSString* _Nullable)softAPSSIDPrefix timeout:(int)timeout wifiGAgentType:(NSArray <NSNumber*>* _Nullable)types;
参数
属性名 |
描述 |
ssid |
待配置的路由 SSID 名 |
key |
待配置的路由密码 |
mode |
配置模式,详细见 GizWifiConfigureMode 枚举定义。 |
softAPSSIDPrefix |
SoftAPMode 模式下 SoftAP 的 SSID 前缀或全名,默认前缀为:XPG-GAgent-。SDK 根据该参数判断手机当前是否连上了设备的 SoftAP 热点。AirLink 模式时传 nil 即可 |
timeout |
配置的超时时间。SDK 默认执行的最小超时时间为30秒。在超时时间内如果无法配置和绑定会回调配网失败 |
wifiGAgentType |
待配置的模组类型,是GizWifiGAgentType 枚举数组。GizWifiGAgentType定义了 SDK 支持的所有模组类型,还定义了一个GizGAgentOther枚举值,用于开发者使用自己的配置库进行设备配置,此时参数传GizGAgentOther即可。此参数传nil、空数组或无有效枚举值,则默认为乐鑫模组 |
回调
如果调用startWithAppInfo接口时指定了待筛选的 productInfo 集合,如果设备被成功配置到路由上并绑定成功,但此设备的productKey不在productInfo指定的productKey中, 会返回配置成功,但不会出现在设备列表中。
- (void)wifiSDK:(GizWifiSDK * _Nonnull)wifiSDK didSetDeviceOnboarding:(GizError * _Nonnull)result device:(GizWifiDevice * _Nullable)device;
回调参数
属性名 |
描述 |
wifiSDK |
回调的 GizWifiSDK 单例 |
result |
配置成功或失败。如果配置失败,其他参数为nil |
device |
配网成功的设备对象 |
代码示例
[GizWifiSDK sharedInstance].delegate = self;
[[GizWifiSDK sharedInstance] setDeviceOnboardingDeploy:@"your_ssid" key:@"your_key" configMode:GizWifiAirLink softAPSSIDPrefix:nil timeout:60 wifiGAgentType:@[@(GizGAgentESP)] ];
[[GizWifiSDK sharedInstance] setDeviceOnboardingDeploy:@"your_ssid" key:@"your_key" configMode:GizWifiSoftAP softAPSSIDPrefix:@"your_gagent_hotspot_prefix" timeout:60 wifiGAgentType:@[@(GizGAgentESP)] ];
- (void)wifiSDK:(GizWifiSDK *)wifiSDK didSetDeviceOnboarding:(NSError *)result device:(GizWifiDevice *)device {
if(result.code == GIZ_SDK_SUCCESS) {
} else {
}
}
[setDeviceOnboarding]
持续获取局域网内未绑定的设备, 直到timeout结束
定义
- (void)setDeviceOnboarding:(int)timeout;
参数
属性名 |
描述 |
timeout |
获取局域网未绑定设备的超时时间;设备列表每次发生变化就会回调一次,到达超时时间会回调GIZ_SDK_ONBOARDING_STOPPED表示获取设备结束 |
回调
- (void)wifiSDK:(GizWifiSDK* _Nonnull)wifiSDK didSetDeviceOnboarding:(GizError* _Nonnull)result deviceList:(NSArray <GizWifiDevice*>* _Nullable)deviceList;
回调参数
属性名 |
描述 |
wifiSDK |
回调的 GizWifiSDK 单例 |
result |
配置成功、失败或超时 |
deviceList |
局域网未绑定的设备列表 |
代码示例
[GizWifiSDK sharedInstance].delegate = self;
[[GizWifiSDK sharedInstance] setDeviceOnboarding:10];
- (void)wifiSDK:(GizWifiSDK* _Nonnull)wifiSDK didSetDeviceOnboarding:(GizError* _Nonnull)result deviceList:(NSArray <GizWifiDevice*>* _Nullable)deviceList {
if(result.code == GIZ_SDK_SUCCESS) {
} else {
}
}
[stopDeviceOnboarding]
停止设备配网,停止后didSetDeviceOnboarding回调中返回的错误码为GIZ_SDK_ONBOARDING_STOPPED
定义
- (void)stopDeviceOnboarding;
回调
- (void)wifiSDK:(GizWifiSDK* _Nonnull)wifiSDK didSetDeviceOnboarding:(GizError* _Nonnull)result mac:(NSString* _Nullable)mac did:(NSString* _Nullable)did productKey:(NSString* _Nullable)productKey;
- (void)wifiSDK:(GizWifiSDK* _Nonnull)wifiSDK didSetDeviceOnboarding:(GizError* _Nonnull)result deviceList:(NSArray <GizWifiDevice*>* _Nullable)deviceList;
回调参数
见【setDeviceOnboardingDeploy】, 【setDeviceOnboarding】
代码示例
[GizWifiSDK sharedInstance].delegate = self;
[[GizWifiSDK sharedInstance] stopDeviceOnboarding];
- (void)wifiSDK:(GizWifiSDK *)wifiSDK didSetDeviceOnboarding:(GizError *)result deviceList:(NSArray<GizWifiDevice *> *)deviceList {
if(result.code == GIZ_SDK_ONBOARDING_STOPPED) {
}
}
- (void)wifiSDK:(GizWifiSDK *)wifiSDK didSetDeviceOnboarding:(GizError *)result mac:(NSString *)mac did:(NSString *)did productKey:(NSString *)productKey {
if(result.code == GIZ_SDK_ONBOARDING_STOPPED) {
}
}
[getSSIDList]
在 Soft-AP 模式时,获得设备的 SSID 列表。SSID列表通过异步回调方式返回
定义
回调
- (void)wifiSDK:(GizWifiSDK *)wifiSDK didGetSSIDList:(NSError *)result ssidList:(NSArray *)ssidList;
回调参数
属性名 |
描述 |
wifiSDK |
回调的 GizWifiSDK 单例 |
result |
详细见 GizWifiErrorCode 枚举定义。GIZ_SDK_SUCCESS 表示成功,其他为失败。失败时,ssidList为 nil |
ssidList |
为若干 GizWifiSSID 实例组成的 SSID 信号列表 |
代码示例
[GizWifiSDK sharedInstance].delegate = self;
[[GizWifiSDK sharedInstance] getSSIDList];
- (void)wifiSDK:(GizWifiSDK *)wifiSDK didGetSSIDList:(NSError *)result ssidList:(NSArray *)ssidList {
if(result.code == GIZ_SDK_SUCCESS) {
} else {
}
}
[getBoundDevices]
获取绑定设备列表。在不同的网络环境下,有不同的处理:
当手机能访问外网时,该接口会向云端发起获取绑定设备列表请求;
当手机不能访问外网时,局域网设备是实时发现的,但会保留之前已经获取过的绑定设备;
手机处于无网模式时,局域网未绑定设备会消失,但会保留之前已经获取过的绑定设备;
定义
- (void)getBoundDevicesSpecialProductKeys:(NSArray<NSString*>* _Nullable)specialProductKeys;
参数
属性名 |
描述 |
specialProductKeys |
指定获取的设备productKey,这个参数只有在启动接口没传productInfo时才会生效 |
回调
以下触发场景触发回调:
getBoundDevices接口调用时触发该回调,错误码代表云端请求状态,设备列表是绑定设备与局域网设备合并之后的集合;
设备列表发生变化时会主动上报时触发该回调,此时错误码GIZ_SDK_SUCCESS,设备列表仍然是合并过的集合。
- (void)wifiSDK:(GizWifiSDK* _Nonnull)wifiSDK didDiscovered:(GizError* _Nonnull)result deviceList:(NSArray <GizWifiDevice*>* _Nullable)deviceList;
回调参数
属性名 |
描述 |
wifiSDK |
回调的 GizWifiSDK 单例 |
result |
详细见 GizWifiErrorCode 枚举定义。GIZ_SDK_SUCCESS 表示成功,其他为失败。失败时,deviceList 为非 nil 集合 |
deviceList |
GizWifiDevice 实例组成的数组,该参数将只返回根据指定productKey筛选过的设备集合。productKey在 getBoundDevices接口调用时指定 |
代码示例
[GizWifiSDK sharedInstance].delegate = self;
[[GizWifiSDK sharedInstance] getBoundDevicesSpecialProductKeys:nil];
- (void)wifiSDK:(GizWifiSDK* _Nonnull)wifiSDK didDiscovered:(GizError* _Nonnull)result deviceList:(NSArray <GizWifiDevice*>* _Nullable)deviceList {
if(result.code != GIZ_SDK_SUCCESS) {
NSLog(@"result: %@", result.localizedDescription);
}
NSLog(@"discovered deviceList: %@", deviceList);
}
[bindDevice]
绑定远端设备到服务器
定义
- (void)bindDevice:(NSString* _Nonnull)mac productKey:(NSString* _Nonnull)productKey alias:(NSString* _Nullable)alias callback:(void (^ _Nullable)(OpenApiResult* _Nonnull result, NSString* _Nullable did))callback;
参数
属性名 |
描述 |
mac |
待绑定设备的mac |
productKey |
待绑定设备的productKey |
alias |
待绑定设备的别名 |
callback |
绑定结果回调 |
回调参数
属性名 |
描述 |
result |
详细见 GizWifiErrorCode 枚举定义。GIZ_SDK_SUCCESS 表示成功,其他为失败 |
did |
绑定成功的设备 did |
代码示例
[[GizWifiSDK sharedInstance] bindDevice:@"your_mac" productKey:@"your_product_key" alias:nil callback:^(OpenApiResult * _Nonnull result, NSString * _Nullable did) {
if (result.error.code == GIZ_SDK_SUCCESS) {
} else {
}
}];
[bindDeviceByQRCode]
根据二维码绑定设备到服务器
定义
- (void)bindDeviceByQRCode:(NSString* _Nonnull)QRContent callback:(void (^ _Nullable)(OpenApiResult* _Nonnull result))callback;
参数
属性名 |
描述 |
QRContent |
二维码内容。二维码需联系机智云FAE提供 |
callback |
绑定设备回调 |
回调参数
属性名 |
描述 |
result |
详细见 GizWifiErrorCode 枚举定义。GIZ_SDK_SUCCESS 表示成功,其他为失败 |
代码示例
[[GizWifiSDK sharedInstance] bindDeviceByQRCode:@"your_QRContent" callback:^(OpenApiResult * _Nonnull result) {
if (result.error.code == GIZ_SDK_SUCCESS) {
} else {
}
}];
[unbindDevices]
从服务器解绑设备
定义
- (void)unbindDevices:(NSArray <GizWifiDevice *>* _Nonnull)devices callback:(void (^ _Nullable)(OpenApiResult* _Nonnull result, NSArray* _Nullable successDids))callback;
参数
属性名 |
描述 |
devices |
待解绑的设备对象集合 |
回调参数
属性名 |
描述 |
result |
详细见 GizWifiErrorCode 枚举定义。GIZ_SDK_SUCCESS 表示成功,其他为失败。失败时,其他回调参数为 nil |
successDids |
成功解绑的设备 did集合 |
代码示例
[[GizWifiSDK sharedInstance] unbindDevices:your_unbind_deviceList callback:^(OpenApiResult *result, NSArray *successDids) {
if(result.error.code == GIZ_SDK_SUCCESS) {
} else {
}
}];
[deviceSafetyRegister]
设备安全注册接口。向云端加密注册设备,注册成功时返回设备did,同时如果用户已登录则会自动绑定已注册成功的设备,绑定成功的设备会主动触发设备列表更新。需注意,安全注册需要productKey和productSecret,这两个信息应在startWithAppInfo接口参数productInfo的指定范围内
定义
+ (void)deviceSafetyRegister:(GizWifiDevice* _Nullable)gateway productKey:(NSString* _Nonnull)productKey devicesInfo:(NSArray<NSDictionary*>* _Nonnull)devicesInfo;
参数
属性名 |
描述 |
gateway |
设备的代理网关,此参数选填。若要注册的设备不需要代理网关,此参数可传nil |
productKey |
设备的产品类型识别码,此参数必填。若填入的productKey不在启动接口参数productInfo的指定范围将不会向云端注册 |
devicesInfo |
要注册的设备信息,可同时传多组设备信息,NSDictionary数组,格式如下:[{mac:"xxx", meshID:"xxx", alias:"xxx", authCode:"xxx"}, ...]mac 设备物理唯一标识,最大32字符长度,NSString类型,必填。meshID 设备组网ID,最大256字符长度,NSString类型,必填。alias 设备别名,最大128字符长度,NSString类型,选填。authCode 设备注册的授权码,32字符长度,由开发者自定义生成,NSString类型,选填。 |
回调
- (void)wifiSDK:(GizWifiSDK* _Nonnull)wifiSDK didDeviceSafetyRegister:(NSArray* _Nullable)successDevices failedDevices:(NSArray* _Nullable)failedDevices;
回调参数
属性名 |
描述 |
wifiSDK |
回调的 GizWifiSDK 单例 |
successDevices |
注册成功的设备信息,NSDictionary数组,nil表示无注册成功的设备。格式如下:[{mac:"xxx", productKey:"xxx", did:"xxx"}, ...]mac 注册成功的设备mac,NSString类型;productKey 注册成功的设备产品类型标识,NSString类型;did 注册成功的设备唯一标识,NSString类型 |
failedDevices |
注册失败的设备信息,NSDictionary数组,nil表示无注册失败的设备。格式如下:[{mac:"xxx", productKey:"xxx", errorCode:"xxx"}, ...]mac 注册失败的设备mac,NSString类型productKey; 注册失败的设备产品类型标识,NSString类型;errorCode 失败的错误码,NSNumber类型。错误码见枚举定义GizWifiErrorCode |
代码示例
[GizWifiSDK sharedInstance].delegate = self;
NSDictionary *deviceInfo = @{@"mac":device.macAddress,
@"meshID":@"your_meshID",
@"alias":@"your_device_alias",
@"authCode":@"your_authCode"
};
[GizWifiSDK deviceSafetyRegister:device productKey:@"your_productKey" devicesInfo:@[deviceInfo]];
- (void)wifiSDK:(GizWifiSDK *)wifiSDK didDeviceSafetyRegister:(NSArray *)successDevices failedDevices:(NSArray *)failedDevices {
for (NSDictionary *successDevice in successDevices) {
}
for (NSDictionary *failedDevice in failedDevices) {
}
}
[deviceSafetyUnbind]
设备安全解绑接口。此接口会在云端把设备的所有关联用户都解绑,可同时解绑多个相同产品类型的设备。但如果设备的产品类型(productKey)不一致将不会解绑任何设备
定义
+ (void)deviceSafetyUnbind:(NSArray<NSDictionary*>* _Nonnull)devicesInfo;
参数
属性名 |
描述 |
devicesInfo |
要解绑的设备信息,格式:[{"device": device, "authCode": "xxx"}],device为GizWifiDevice对象,authCode为授权码。authCode不是必填参数,若没有授权码则不需要填写此字段 |
回调
- (void)wifiSDK:(GizWifiSDK* _Nonnull)wifiSDK didDeviceSafetyUnbind:(NSArray* _Nullable)failedDevices;
回调参数
属性名 |
描述 |
wifiSDK |
回调的 GizWifiSDK 单例 |
failedDevices |
解绑失败的设备,NSDictionary数组,nil表示全部解绑成功。字典格式如下:[{device:xxx, errorCode:xxx}, ...]device 解绑失败的设备对象,GizWifiDevice类型errorCode 失败的错误码,NSNumber类型,见GizWifiErrorCode枚举定义 |
代码示例
[GizWifiSDK sharedInstance].delegate = self;
NSDictionary *deviceInfo = @{@"device":device,
@"authCode":@"your_authCode"};
[GizWifiSDK deviceSafetyUnbind:@[deviceInfo]];
- (void)wifiSDK:(GizWifiSDK *)wifiSDK didDeviceSafetyUnbind:(NSArray *)failedDevices {
for (NSDictionary *failedDevice in failedDevices) {
}
}
[setUid]
设置用户uid和token
定义
- (void)setUid:(NSString* _Nonnull)uid token:(NSString* _Nonnull)token;
参数
属性名 |
描述 |
uid |
在登录或注册成功获取到的用户唯一id |
token |
在登录或注册成功获取到的用户token |
回调
- (void)wifiSDK:(GizWifiSDK * _Nonnull)wifiSDK didSetUid:(GizError * _Nonnull)result;
回调参数
属性名 |
描述 |
wifiSDK |
回调的 GizWifiSDK 单例 |
result |
详细见 GizWifiErrorCode 枚举定义。GIZ_SDK_SUCCESS 表示成功,其他为失败。失败时,其他回调参数为 nil |
代码示例
[GizWifiSDK sharedInstance].delegate = self;
[[GizWifiSDK sharedInstance] setUid:@"your_uid" token:@"your_token"];
- (void)wifiSDK:(GizWifiSDK * _Nonnull)wifiSDK didSetUid:(GizError * _Nonnull)result {
}
[registerUser]
用户注册。 需指定用户类型注册。手机用户的用户名是手机号,邮箱用户的用户名是邮箱、普通用户的用户名可以是普通用户名;
注意:如果邮箱注册启用了邮箱激活,会返回注册成功,但不会返回uid、token
定义
- (void)registerUser:(NSString* _Nonnull)username password:(NSString* _Nonnull)password verifyCode:(NSString* _Nullable)code accountType:(GizUserAccountType)accountType callback:(void (^ _Nullable)(OpenApiLoginResult* _Nonnull result))callback;
参数
属性名 |
描述 |
username |
注册用户名(可以是手机号、邮箱或普通用户名) |
password |
注册密码 |
code |
手机短信验证码。短信验证码注册后就失效了,不能被再次使用 |
accountType |
用户类型,详细见 GizUserAccountType 枚举定义。注册手机号时,此参数指定为手机用户,注册邮箱时,此参数指定为邮箱用户,注册普通用户名时,此参数指定为普通用户 |
callback |
注册用户的回调 |
回调参数
属性名 |
描述 |
result |
详细见 GizWifiErrorCode 枚举定义。GIZ_SDK_SUCCESS 表示成功,其他为失败。失败时,其他回调参数为 nil |
代码示例
[[GizWifiSDK sharedInstance] registerUser:@"your_register_username" password:@"your_password" verifyCode:nil accountType:GizUserNormal callback:^(OpenApiLoginResult * _Nonnull result) {
if(result.error.code == GIZ_SDK_SUCCESS) {
} else {
}
}];
[userLogin]
用户登录。需使用注册成功的用户名、密码进行登录,可以是手机用户名、邮箱用户名或普通用户名
定义
- (void)userLogin:(NSString* _Nonnull)username password:(NSString* _Nonnull)password callback:(void (^ _Nullable)(OpenApiLoginResult* _Nonnull result))callback;
参数
属性名 |
描述 |
username |
登录用户名 |
password |
登录密码 |
callback |
登录结果回调 |
回调参数
属性名 |
描述 |
result |
详细见 GizWifiErrorCode 枚举定义。GIZ_SDK_SUCCESS 表示成功,其他为失败。失败时,uid、token为 nil |
代码示例
[[GizWifiSDK sharedInstance] userLogin:@"your_username" password:@"your_password" callback:^(OpenApiLoginResult * _Nonnull result) {
if(result.error.code == GIZ_SDK_SUCCESS) {
} else {
}
}];
[dynamicLogin]
动态验证码登录。登录用户名为手机号,以手机收到的登录验证码登录
定义
- (void)dynamicLogin:(NSString* _Nonnull)phone code:(NSString* _Nonnull)code callback:(void (^ _Nullable)(OpenApiLoginResult* _Nonnull result))callback;
参数
属性名 |
描述 |
phone |
手机号 |
code |
手机短信验证码。短信验证码注册后就失效了,不能被再次使用 |
回调参数
属性名 |
描述 |
result |
详细见 GizWifiErrorCode 枚举定义。GIZ_SDK_SUCCESS 表示成功,其他为失败。失败时,其他回调参数为 nil |
代码示例
[self.sdk dynamicLogin:@"your_phone" code:@"your_code" callback:^(OpenApiLoginResult * _Nonnull result) {
if(result.error.code == GIZ_SDK_SUCCESS) {
} else {
}
}];
[userLoginAnonymous]
匿名登录。匿名方式登录,不需要注册用户账号.
定义
- (void)userLoginAnonymous:(void (^ _Nullable)(OpenApiLoginResult* _Nonnull result))callback;
回调参数
属性名 |
描述 |
result |
详细见 GizWifiErrorCode 枚举定义。GIZ_SDK_SUCCESS 表示成功,其他为失败。失败时,其他回调参数为 nil |
代码示例
[[GizWifiSDK sharedInstance] userLoginAnonymous:^(OpenApiLoginResult * _Nonnull result) {
if(result.error.code == GIZ_SDK_SUCCESS) {
} else {
}
}];
[userLoginWithThirdAccount]
第三方账号登录(第三方接口登录方式)
定义
- (void)userLoginWithThirdAccount:(GizThirdAccountType)thirdAccountType uid:(NSString* _Nonnull)uid token:(NSString* _Nonnull)token tokenSecret:(NSString* _Nullable)tokenSecret callback:(void (^ _Nullable)(OpenApiLoginResult* _Nonnull result))callback;
参数
属性名 |
描述 |
thirdAccountType |
第三方账号类型,详细见 GizThirdAccountType 枚举定义 |
uid |
通过第三方平台 api 方式登录后得到的 uid |
token |
通过第三方平台api方式 登录后得到的 token |
tokenSecret |
推特账号登录时需要通过推特平台api方式得到此参数,其他第三方账号此参数可传nil |
callback |
登录结果回调 |
回调参数
属性名 |
描述 |
result |
详细见 GizWifiErrorCode 枚举定义。GIZ_SDK_SUCCESS 表示成功,其他为失败。失败时,其他回调参数为 nil |
代码示例
[[GizWifiSDK sharedInstance] userLoginWithThirdAccount:GizThirdQQ uid:@"your_uid" token:@"your_token" tokenSecret:nil callback:^(OpenApiLoginResult * _Nonnull result) {
if(result.error.code == GIZ_SDK_SUCCESS) {
} else {
}
}];
[transAnonymousUser]
匿名用户转换,可转换为手机用户或者普通用户。注意,待转换的帐号必须是还未注册过的
定义
- (void)transAnonymousUser:(NSString* _Nonnull)username password:(NSString* _Nonnull)password verifyCode:(NSString* _Nullable)code accountType:(GizUserAccountType)accountType callback:(void (^ _Nullable)(OpenApiResult* _Nonnull result))callback;
参数
属性名 |
描述 |
username |
待转换的普通账号或手机号 |
password |
转换后的帐号密码 |
code |
转换为手机用户时要使用的手机短信验证码 |
accountType |
用户类型,详细见 GizThirdAccountType 枚举定义。待转换的用户名是手机号时,此参数指定为GizUserPhone,待转换用户名是普通账号时,此参数指定为GizUserNormal |
回调参数
属性名 |
描述 |
result |
详细见 GizWifiErrorCode 枚举定义。GIZ_SDK_SUCCESS 表示成功,其他为失败 |
代码示例
[GizWifiSDK sharedInstance].delegate = self;
[[GizWifiSDK sharedInstance] transAnonymousUser:@"your_user_name" password:@"your_password" verifyCode:nil accountType:GizUserNormal callback:^(OpenApiResult * _Nonnull result) {
if(result.error.code == GIZ_SDK_SUCCESS) {
} else {
}
}];
[userLogout]
注销用户,会将用户已经订阅的设备取消订阅,并删除远程设备列表
定义
回调
- (void)wifiSDK:(GizWifiSDK * _Nonnull)wifiSDK didUserLogout:(GizError * _Nonnull)result;
回调参数
属性名 |
描述 |
wifiSDK |
回调的 GizWifiSDK 单例 |
result |
详细见 GizWifiErrorCode 枚举定义。GIZ_SDK_SUCCESS 表示成功,其他为失败 |
代码示例
[GizWifiSDK sharedInstance].delegate = self;
[[GizWifiSDK sharedInstance] userLogout];
- (void)wifiSDK:(GizWifiSDK * _Nonnull)wifiSDK didUserLogout:(GizError * _Nonnull)result {
}
[changeUserPassword]
修改用户密码
定义
- (void)changeUserPassword:(NSString* _Nonnull)oldPassword newPassword:(NSString* _Nonnull)newPassword callback:(void (^ _Nullable)(OpenApiResult* _Nonnull result))callback;
参数
属性名 |
描述 |
oldPassword |
旧密码 |
newPassword |
新密码 |
callback |
回调 |
回调参数
属性名 |
描述 |
result |
详细见 GizWifiErrorCode 枚举定义。GIZ_SDK_SUCCESS 表示成功,其他为失败。失败时,其他回调参数为 nil |
代码示例
[[GizWifiSDK sharedInstance] changeUserPassword:@"your_old_password" newPassword:@"your_new_password" callback:^(OpenApiResult * _Nonnull result) {
if(result.error.code == GIZ_SDK_SUCCESS) {
} else {
}
}];
[changePhoneOrEmail]
修改账号,只能支持修改手机号或邮箱
定义
- (void)changePhoneOrEmail:(NSString * _Nonnull)username code:(NSString * _Nullable)code accountType:(GizUserAccountType)accountType callback:(void (^ _Nullable)(OpenApiResult * _Nonnull result))callback;
参数
属性名 |
描述 |
username |
手机号/邮箱 |
code |
修改手机号,这里需要传验证码 |
accountType |
账号类型:传GizUserPhone/GizUserEmail |
callback |
修改账号结果回调 |
回调参数
属性名 |
描述 |
result |
详细见 GizWifiErrorCode 枚举定义。GIZ_SDK_SUCCESS 表示成功,其他为失败。失败时,其他回调参数为 nil |
代码示例
[[GizWifiSDK sharedInstance] changePhoneOrEmail:@"your_email" code:nil accountType:GizUserEmail callback:^(OpenApiResult * _Nonnull result) {
if(result.error.code == GIZ_SDK_SUCCESS) {
} else {
}
}];
[resetPassword]
重置密码。手机号重置密码时通过手机短信验证码重置,邮箱重置密码时需通过邮箱密码重置链接重置
定义
- (void)resetPassword:(NSString* _Nonnull)username verifyCode:(NSString* _Nullable)code newPassword:(NSString* _Nonnull)newPassword accountType:(GizUserAccountType)accountType callback:(void (^ _Nullable)(OpenApiResult* _Nonnull result))callback;
参数
属性名 |
描述 |
username |
待重置密码的手机号或邮箱 |
code |
重置手机用户密码时需要使用手机短信验证码(通过 requestSendPhoneSMSCode 方法获取) |
newPassword |
新密码。邮箱重置密码时不需要填充密码,可指定为nil |
accountType |
用户类型,详细见 GizThirdAccountType 枚举定义。待重置密码的用户名是手机号时,此参数指定为手机用户,待重置密码的用户名是邮箱时,此参数指定为邮箱用户 |
回调参数
属性名 |
描述 |
result |
详细见 GizWifiErrorCode 枚举定义。GIZ_SDK_SUCCESS 表示成功,其他为失败。失败时,其他回调参数为 nil |
代码示例
[[GizWifiSDK sharedInstance] resetPassword:@"your_phone_number" verifyCode:@"your_verify_code" newPassword:@"your_new_password" accountType:GizUserPhone callback:^(OpenApiResult * _Nonnull result) {
if(result.error.code == GIZ_SDK_SUCCESS) {
} else {
}
}];
[getUserInfo]
获取用户信息
定义
- (void)getUserInfo:(void (^ _Nullable)(OpenApiResult* _Nonnull result, GizOpenApiUser*_Nullable userInfo))callback;
参数
属性名 |
描述 |
callback |
获取用户信息结果回调 |
回调参数
属性名 |
描述 |
result |
详细见 GizWifiErrorCode 枚举定义。GIZ_SDK_SUCCESS 表示成功,其他为失败 |
userInfo |
用户信息,详细见 GizOpenApiUser类 |
代码示例
[[GizWifiSDK sharedInstance] getUserInfo:^(OpenApiResult * _Nonnull result, GizOpenApiUser * _Nullable userInfo) {
if(result.error.code == GIZ_SDK_SUCCESS) {
} else {
}
}];
[changeUserInfo]
修改用户个人信息。
定义
- (void)changeUserInfo:(GizOpenApiUser * _Nonnull)additionalInfo callback:(void (^ _Nullable)(OpenApiResult * _Nonnull result))callback;
参数
属性名 |
描述 |
additionalInfo |
待修改的个人信息,详细见 GizOpenApiUser 类定义。 |
callback |
修改用户个人信息回调 |
回调参数
属性名 |
描述 |
result |
详细见 GizWifiErrorCode 枚举定义。GIZ_SDK_SUCCESS 表示成功,其他为失败 |
代码示例
GizOpenApiUser *newUserInfo = [GizOpenApiUser new];
newUserInfo.userGender = GizUserGenderFemale;
newUserInfo.name = @"your_new_name";
newUserInfo.language = GIZ_LANGUAGE_EN;
newUserInfo.address = @"your_address";
newUserInfo.birthday = @"your_birthday";
[[GizWifiSDK sharedInstance] changeUserInfo:newUserInfo callback:^(OpenApiResult * _Nonnull result) {
if(result.error.code == GIZ_SDK_SUCCESS) {
} else {
}
}];
[requestSendPhoneSMSCode]
通过手机号请求短信验证码
定义
- (void)requestSendPhoneSMSCode:(NSString* _Nonnull)phone callback:(void (^ _Nullable)(OpenApiResult* _Nonnull result))callback;
参数
回调参数
属性名 |
描述 |
result |
详细见 GizWifiErrorCode 枚举定义。GIZ_SDK_SUCCESS 表示成功,其他为失败。失败时,其他回调参数为 nil |
代码示例
[GizWifiSDK sharedInstance].delegate = self;
[[GizWifiSDK sharedInstance] requestSendPhoneSMSCode:phone callback:^(OpenApiResult * _Nonnull result) {
if(result.error.code == GIZ_SDK_SUCCESS) {
} else {
}
}];
[setLogLevel]
设置日志输出级别。该级别指日志在调试终端和log文件的输出级别,默认是全部输出的。
日志文件存放在Documents目录下:GizWifiSDK/GizSDKLog/
定义
+ (void)setLogLevel:(GizLogPrintLevel)logPrintLevel;
参数
属性名 |
描述 |
logLevel |
日志输出级别,参考 GizLogPrintLevel 定义 |
代码示例
[[GizWifiSDK sharedInstance] setLogLevel: GizLogPrintAll];
[encryptLog]
设置日志加密。
定义
代码示例
[channelIDBind]
绑定推送的ID到当前用户下,以接收设备的通知事件
定义
- (void)channelIDBind:(NSString* _Nullable)channelID alias:(NSString* _Nullable)alias pushType:(GizPushType)pushType callback:(void (^ _Nullable)(OpenApiResult* _Nonnull result))callback;
参数
属性名 |
描述 |
channelID |
从第三方推送平台获取的推送ID |
alias |
推送别名,只在极光推送中产生作用 |
pushType |
推送类型,详细见 GizPushType 枚举定义 |
callback |
绑定推送id回调 |
回调参数
属性名 |
描述 |
result |
详细见 GizWifiErrorCode 枚举定义。result.code 为 GIZ_SDK_SUCCESS 表示成功,其他为失败。失败时,其他回调参数为 nil |
代码示例
[[GizWifiSDK sharedInstance] channelIDBind:@"your_channelID" alias:nil pushType:GizPushJiGuang callback:^(OpenApiResult * _Nonnull result) {
if(result.error.code == GIZ_SDK_SUCCESS) {
} else {
}
}];
[channelIDUnBind]
解绑推送ID与当前用户的绑定关系,以解除接收设备的通知事件
定义
- (void)channelIDUnBind:(NSString* _Nonnull)channelID callback:(void (^ _Nullable)(OpenApiResult* _Nonnull result))callback;
参数
属性名 |
描述 |
channelID |
从第三方推送平台获取的推送ID |
callback |
解绑推送id回调 |
回调参数
属性名 |
描述 |
result |
详细见 GizWifiErrorCode 枚举定义。result.error.code 为 GIZ_SDK_SUCCESS 表示成功,其他为失败。失败时,其他回调参数为 nil |
代码示例
[[GizWifiSDK sharedInstance] channelIDUnBind:@"dsdada" callback:^(OpenApiResult * _Nonnull result) {
if(result.error.code == GIZ_SDK_SUCCESS) {
} else {
}
}];
[userFeedback]
用户问题日志反馈接口。此接口无回调,调用后就会上传信息。目前信息上传后,需要联系机智云FAE查看
定义
+ (void)userFeedback:(NSString* _Nullable)contactInfo feedbackInfo:(NSString* _Nullable)feedbackInfo sendLog:(BOOL)sendLog;
参数
属性名 |
描述 |
contactInfo |
用户的联系方式。此参数为选填 |
feedbackInfo |
用户反馈的信息。此参数为选填 |
sendLog |
是否发送问题日志。如果前面两个参数都没填,则默认发送问题日志 |
代码示例
[GizWifiSDK userFeedback:@"your_phone" feedbackInfo:@"your_message" sendLog:YES];
[getCurrentCloudService]
查询当前使用的云服务域名信息
定义
+ (NSDictionary* _Nonnull)getCurrentCloudService;
返回值类型
{"appApi" : "xxx", // NSString类型 "push" : "xxx"// NSString类型 }
代码示例
NSDictionary *cloudServer = [GizWifiSDK getCurrentCloudService];
[getUserTerm]
获取用户协议内容
定义
- (void)getUserTerm:(GizUserTermType)termType callback:(void (^ _Nonnull)(OpenApiResult* _Nonnull result, NSString* _Nullable termUrl))callback;
参数
属性名 |
描述 |
termType |
协议类型, 详细见GizUserTermType枚举 |
callback |
请求回调 |
回调参数
属性名 |
描述 |
result |
详细见 OpenApiResult 定义 |
termUrl |
获取到的协议链接 |
代码示例
[[GizWifiSDK sharedInstance] getUserTerm:GizUserTermAgreement callback:^(OpenApiResult * _Nonnull result, NSString * _Nonnull termUrl) {
NSLog(@"termUrl = %@, result = %@", termUrl, result.error);
}];
[checkUserTerm]
检查用户协议
定义
- (void)checkUserTerm:(void (^ _Nonnull)(OpenApiResult* _Nonnull result, BOOL needToSign, NSArray<GizUserTerm*>* _Nullable terms))callback;
参数
回调参数
属性名 |
描述 |
result |
详细见 OpenApiResult 定义 |
needToSign |
返回是否确认过用户协议, YES: 没确认 NO: 已确认 |
terms |
协议类型数组,详细见《GizUserTerm》类 |
代码示例
[[GizWifiSDK sharedInstance] checkUserTerm:^(OpenApiResult * _Nonnull result, BOOL needToSign, NSArray<GizUserTerm *> * _Nonnull terms) {
NSLog(@"needToSign = %d, terms = %@, error = %@", needToSign, terms, result.error);
}];
[confirmUserTerm]
确认用户协议
定义
- (void)confirmUserTerm:(NSArray<GizUserTerm*>* _Nonnull)terms callback:(void (^ _Nonnull)(OpenApiResult* _Nonnull result))callback;
参数
属性名 |
描述 |
terms |
协议类型数组 |
callback |
请求回调 |
回调参数
属性名 |
描述 |
result |
详细见 OpenApiResult 定义 |
代码示例
GizUserTerm *term = [GizUserTerm new];
term.termType = GizUserTermAgreement;
[self.sdk confirmUserTerm:@[term] callback:^(OpenApiResult * _Nonnull result) {
NSLog(@"error = %@", result.error);
}];