更新时间:2025-01-08 06:31:16下载pdf
设备日志可以提高排查设备问题的效率,为了快速定位用户问题,建议设备支持此功能。ThingSmartCameraType
的属性 extraAbility
开放了和设备日志上传相关的接口。
接口说明
@property (nonatomic, assign, readonly) BOOL hasRespondToUploadLogCmdAbility;
接口说明
- (void)deliverUploadLogCmdWithConfig:(id<ThingSmartCameraUploadLogConfig>)config success:(nullable ThingSuccessHandler)success failure:(nullable ThingFailureError)failure;
参数说明
参数 | 说明 |
---|---|
config |
配置,可设置超时时长,默认 60s |
success |
成功回调 |
failure |
失败回调 |
通过设置 extraAbility
的 debugAbilityDelegate
监听日志是否上传完成。
接口说明
- (void)cameraDidUploadLogWithResult:(BOOL)result extInfo:(nullable NSDictionary *)extInfo;
参数说明
参数 | 说明 |
---|---|
result |
完成结果,YES 表示成功 |
extInfo |
扩展信息 |
示例代码
Objective-C:
@interface SampleModelUploadLogConfig : NSObject <ThingSmartCameraUploadLogConfig>
@end
@implementation SampleModelUploadLogConfig
@synthesize uploadTimeout;
@end
@interface SampleViewController : SampleViewController <ThingSmartCameraDelegate,ThingSmartCameraDebugAbilityDelegate>
@end
@implementation SampleViewController
- (void)deliverUploadLogCmd {
// deviceModel 为设备列表中的摄像机设备的数据模型
NSInteger p2pType = [deviceModel p2pType];
id<ThingSmartCameraType> camera = [ThingSmartCameraFactory cameraWithP2PType:@(p2pType) deviceId:deviceModel.devId delegate:self];
BOOL hasAbility = camera.extraAbility.hasRespondToUploadLogCmdAbility;
if (hasAbility == NO) {
return;
}
SampleModelUploadLogConfig *uploadLogConfig = [[SampleModelUploadLogConfig alloc] init];
uploadLogConfig.uploadTimeout = 60;
camera.extraAbility.debugAbilityDelegate = self;
[camera.extraAbility deliverUploadLogCmdWithConfig:uploadLogConfig success:^{
} failure:^(NSError * _Nonnull error) {
}];
}
#pragma mark - ThingSmartCameraDelegate
#pragma mark - ThingSmartCameraDebugAbilityDelegate
- (void)cameraDidUploadLogWithResult:(BOOL)result extInfo:(NSDictionary *)extInfo {
if (result == YES) {
NSLog(@"upload log success");
}
}
@end
Swift:
class SampleModelUploadLogConfig: NSObject, ThingSmartCameraUploadLogConfig {
var uploadTimeout: NSTimeInterval
init(uploadTimeout: NSTimeInterval) {
self.uploadTimeout = uploadTimeout
}
}
class SampleViewController: UIViewController {
var deviceModel: ThingSmartDeviceModel?
private func deliverUploadLogCmd {
let p2pType: NSNumber = NSNumber(value: deviceModel.p2pType())
let camera = ThingSmartCameraFactory.camera(withP2PType: p2pType, deviceId: deviceModel.devId, delegate: self)
let extraAbility ? ThingSmartCameraExtraAbility = camera.extraAbility
guard let hasAbility = extraAbility.hasRespondToUploadLogCmdAbility else {
print("the device has no debug ability")
return
}
extraAbility.debugAbilityDelegate = self
let uploadLogConfig = SampleModelUploadLogConfig(uploadTimeout: 60)
extraAbility.deliverUploadLogCmd(with: uploadLogConfig, success: {}, failure: {error in
print("deliver cmd failed")
})
}
}
extension SampleViewController: ThingSmartCameraDelegate,ThingSmartCameraDebugAbilityDelegate {
func cameraDidUploadLog(withResult result: Bool, extInfo: [AnyHashable : Any]?) {
if result == false {
return
}
print("upload log success")
}
}
该内容对您有帮助吗?
是意见反馈该内容对您有帮助吗?
是意见反馈