尝试动态设置蓝牙对话。管理以追查我无法弄清楚的问题。在peripheralManagerDidUpdateState内;设置服务。现在这个代码有效!
func peripheralManagerDidUpdateState(peripheral: CBPeripheralManager) {
if (peripheral.state != .PoweredOn) {
return;
}
if (peripheral.state == .PoweredOn) {
transferCharacteristic = CBMutableCharacteristic(type: cbtransfer, properties: .Notify, value: nil, permissions: .Readable)
transferEvak = CBMutableCharacteristic(type: cbevak, properties: .Notify, value: nil, permissions: .Readable)
transferPlay = CBMutableCharacteristic(type: characteristicsArray[3], properties: .Notify, value: nil, permissions: .Readable)
transferService = CBMutableService(type: cbservice, primary: true)
transferService.characteristics = [transferCharacteristic, transferEvak,transferPlay]
peripheralManager!.addService(transferService)
peripheralManager!.startAdvertising([CBAdvertisementDataServiceUUIDsKey :[cbservice]])
注意characteristicArray是使用我动态创建的UUID定义和填充的。
var characteristicsArray = [CBUUID]()
确定;但我真的不想在transferService.characteristics中逐个添加特性;我想做这样的事情。
transferService.characteristics = CBMutableServicesCharacteristicsArray
但这不起作用,似乎我必须将transferService.characteristics定义为值的静态数组?我错过了什么?为什么呢?