tencentyun / qcloud-sdk-ios

腾讯云服务iOS终端SDK
http://qcloud.com
38 stars 26 forks source link

QCloudCOSXMLService.hasService(forKey: "")多次调用返回false,导致注册crash #49

Closed kb100824 closed 2 years ago

kb100824 commented 2 years ago

 crash日志总是输出:'默认的COSXMLService已存在,如有新的配置,请通过 registerCOSXMLWithConfiguration:withKey:重新注册' 

v5.9.4版本-----目前只能是通过新增一个全局变量来保存当前的区域名进行判断控制解决多次初始化crash问题:

具体方案如下:

 /// 保存当前地域名
    private var currentRegionName: String = "___regionxxxx___"

       QCloudCOSXMLService.removeCOSXML(withKey: "regionName")

        /// sdk的api有问题 QCloudCOSXMLService.hasService(forKey: "regionName")
        if currentRegionName == "regionName" {
            QCloudCOSXMLService.registerCOSXML(with: configure, withKey: "regionName")
            QCloudCOSTransferMangerService.registerCOSTransferManger(with: configure, withKey: "regionName")
        } else {
            QCloudCOSXMLService.registerDefaultCOSXML(with: configure)
            QCloudCOSTransferMangerService.registerDefaultCOSTransferManger(with: configure)
        }
        currentRegionName = "regionName"
wangbo1185742894 commented 2 years ago

具体什么问题?

kb100824 commented 2 years ago

初始化注册regionName 有crash,你看下我贴的代码啊

wangbo1185742894 commented 2 years ago

1:默认service确定注册一次,建议放到service里。2:自定义service注册之前确保使用的key没有被注册过。

kb100824 commented 2 years ago

@wangbo1185742894 也就是说自定义regionName,必须要保证这两句注册代码最终执行一次?

       QCloudCOSXMLService.registerDefaultCOSXML(with: configure)
        QCloudCOSTransferMangerService.registerDefaultCOSTransferManger(with: configure)
wangbo1185742894 commented 2 years ago

默认的service只能注册一次,自定义的service同一个key只能注册一次

kb100824 commented 2 years ago

tks

wangbo1185742894 commented 2 years ago

不客气,不过下个版本这里会优化,重复注册是覆盖效果,不会crash