更新时间:2024-06-05 09:04:03下载pdf
NB-IoT 设备采用的是低功耗广域网 (LPWA) 技术,它可以在已建成的移动网络上更简单、更高效地连接物联网设备。Cube App SDK 为 NB-IoT 设备配网的第一步就是扫描 NB-IoT 设备的二维码,查询设备 ID 进行设备配网。
parseQRCode
是一个用于解析设备上的 QR 码的方法。可扫描设备二维码获取 URL 和设备 UUID。
参数说明
content
:QR 码的内容。success
:成功解析 QR 码后的回调函数。可以获取到设备 token。failure
:解析 QR 码出错时的回调函数。示例代码
Objective-C
[ThingSmartActivator parseQRCode:@"yourQRCodeContent" success:^(id result) {
NSDictionary *qrCodeDict = (NSDictionary *)result;
NSLog(@"Action Name: %@", [qrCodeDict objectForKey:@"actionName"]);
NSLog(@"Action Data: %@", [qrCodeDict objectForKey:@"actionData"]);
} failure:^(NSError *error) {
NSLog(@"Error: %@", error.localizedDescription);
}];
Swift
ThingSmartActivator.parseQRCode("yourQRCodeContent", success: { result in
guard let qrCodeDict = result as? [String: Any] else {
return
}
print("Action Name: \(qrCodeDict["actionName"] ?? "")")
print("Action Data: \(qrCodeDict["actionData"] ?? "")")
}) { error in
print("Error: \(error.localizedDescription)")
}
ThingSmartNBDeviceActivator
类用于将 NB-IoT 设备绑定到云服务。
方法
- (void)requestNBDeviceBindWithParam:(ThingSmartNBDeviceBindRequestData *)param success:(void(^)(ThingSmartNBDeviceBindResponseData *result))success failure:(ThingFailureError)failure;
此方法用于将 NB-IoT 设备绑定到云服务。
参数
param
:绑定请求参数的 ThingSmartNBDeviceBindRequestData
对象。success
:成功回调,返回 ThingSmartNBDeviceBindResponseData
对象。failure
:失败回调,返回错误信息。ThingSmartNBDeviceBindRequestData
类用于创建设备绑定请求参数。
属性
hid
:字符串类型,表示设备的 token。来自上文中的 parseQRCode
方法。timeZone
:字符串类型,表示设备的时区。gid
:长整型,表示设备的空间 ID。Objective-C
ThingSmartNBDeviceBindRequestData *requestData = [[ThingSmartNBDeviceBindRequestData alloc] init];
requestData.hid = @"your_device_token";
requestData.timeZone = @"your_device_time_zone";
requestData.gid = your_space_id;
ThingSmartNBDeviceActivator *activator = [[ThingSmartNBDeviceActivator alloc] init];
[activator requestNBDeviceBindWithParam:requestData success:^(ThingSmartNBDeviceBindResponseData *result) {
// Handle success
NSLog(@"Device bind success: %@", result);
} failure:^(NSError *error){
// Handle failure
NSLog(@"Device bind failure: %@", error);
}];
Swift
let requestData = ThingSmartNBDeviceBindRequestData()
requestData.hid = "your_device_token"
requestData.timeZone = "your_device_time_zone"
requestData.gid = your_space_id
let activator = ThingSmartNBDeviceActivator()
activator.requestNBDeviceBind(withParam: requestData, success: { (result) in
// Handle success
print("Device bind success: \(result)")
}) { (error) in
// Handle failure
print("Device bind failure: \(error)")
}
该内容对您有帮助吗?
是意见反馈该内容对您有帮助吗?
是意见反馈