//固件升级代码(设置代理之类的就不说了,代码这么多原理也看不过来) // DFUFirmware *selectedFirmware = [[DFUFirmware alloc] initWithZipFile:firmWareData]; dispatch_queue_t eventQueue = dispatch_queue_create("com.ota.updater", DISPATCH_QUEUE_CONCURRENT); DFUServiceInitiator * dfuInitiator = [[DFUServiceInitiator alloc] initWithQueue:eventQueue delegateQueue:eventQueue progressQueue:eventQueue loggerQueue:eventQueue]; dfuInitiator = [dfuInitiator withFirmware:selectedFirmware]; dfuInitiator.delegate = self; dfuInitiator.progressDelegate = self; dfuInitiator.logger = self; ///这个设置无关精要 //dfuInitiator.packetReceiptNotificationParameter = 4; ///之前一直处理不成功,自动断开连接然后又一直重试连接,重试是sdk搞出来的事情,最后发现是一直在尝试给硬件设置名称(我们的硬件这类命令发过去都是要先绑定和授权的)所以一直失败,由此设置这个属性不让它进行这种莫名其妙的操作,接下来就是见证奇迹的时刻了 dfuInitiator.alternativeAdvertisingNameEnabled = NO; dfuInitiator.enableUnsafeExperimentalButtonlessServiceInSecureDfu = YES; self.dfuController = [[dfuInitiator withFirmware:selectedFirmware] startWithTarget:peripheral];
不进行这个配置,使用其他工具 nRF Connect上报的错误信息(后来看这个报错也比较明确说了处理方式)
[Callback] Central Manager did disconnect peripheral
Disconnected by the remote device
Buttonless service not configured, see: https://devzone.nordicsemi.com/f/nordic-q-a/59881/advertising-rename-feature-not-working/243566#243566. To workaround, disable alternative advertising name.
Connecting to T001...
centralManager.connect(peripheral, options: nil)
[Callback] Central Manager did connect peripheral
Connected to T001
Discovering services...
系统给出的断连错误信息:
Error Domain=CBErrorDomain Code=6 "The connection has timed out unexpectedly." UserInfo={NSLocalizedDescription=The connection has timed out unexpectedly.}