标签:style blog http color os io ar for div
今天App写到了蓝牙重连的阶段,以前针对sdk 6.0写的代码,蓝牙设备的回复是通过
- (void)retrievePeripherals:(NSArray *)peripheralUUIDs
然后回调
centralManager:didRetrievePeripherals:
函数来得到可以回复设备的Array。
在SDK7之后,- (void)retrievePeripherals:(NSArray *)peripheralUUIDs被废除了,取而代之的是
retrievePeripheralsWithIdentifiers:
这个函数会Returns a list of known peripherals by their identifiers.
刚开始我还以为调用了这个函数,还要在回调函数中完成连接操作,后来才发现,SDK6.0中的回调函数就是返回a list of known peripherals by their identifiers. 而现在不用通过回调函数,retrievePeripheralsWithIdentifiers:的返回值就是 a list of known peripherals by their identifiers. 这样代码更简洁了,这要直接对这些外设直接进行连接操作就可以了。
简单代码如下:
var identiferArray = Array<NSUUID>() identiferArray.append(peri.identifer)//将identider加入得到identiferArray var knownPeripherals = myCentralManager!.retrievePeripheralsWithIdentifiers(identiferArray) for p in knownPeripherals { myCentralManager!.connectPeripheral(p, options: nil) }
iOS8 蓝牙设备的重连接(retrieve) Swift实现
标签:style blog http color os io ar for div
原文地址:http://www.cnblogs.com/scaptain/p/3942244.html