设备日志上传

更新时间:2025-01-08 06:31:16下载pdf

设备日志可以提高排查设备问题的效率,为了快速定位用户问题,建议设备支持此功能。ThingSmartCameraType 的属性 extraAbility 开放了和设备日志上传相关的接口。

IPC 嵌入式 SDK 3.10.6 及以上版本支持 App SDK 下发 设备上传日志 指令,更低的版本只支持平台下发 设备上传日志 指令。

是否支持下发上传日志指令

接口说明

@property (nonatomic, assign, readonly) BOOL hasRespondToUploadLogCmdAbility;

下发上传日志指令

接口说明

- (void)deliverUploadLogCmdWithConfig:(id<ThingSmartCameraUploadLogConfig>)config success:(nullable ThingSuccessHandler)success failure:(nullable ThingFailureError)failure;

参数说明

参数 说明
config 配置,可设置超时时长,默认 60s
success 成功回调
failure 失败回调

日志上传完成

通过设置 extraAbilitydebugAbilityDelegate 监听日志是否上传完成。

接口说明

- (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")
    }
}