ios - CoreBluetooth: scanForPeripheralsWithServices not working with service array -


i'm developing ble application ios (swift) , i've found strange behaviour.. test has 2 controllers, 1 centralmanager role , other peripheralmanager role..

here's code (summary):

parameters.swift:

... // custome uuid created in console let transfer_service_uuid = cbuuid(string: "fb694b90-f49e-....-....-171bba78f846") ... 

peripheral.swift

... var pmanager = cbperipheralmanager() var transferservice = cbmutableservice()  override func viewdidload() {     super.viewdidload()     pmanager = cbperipheralmanager(delegate: self, queue: nil) }  func peripheralmanagerdidupdatestate(peripheral: cbperipheralmanager!) {     if(peripheral.state == cbperipheralmanagerstate.poweredon) {         transferservice = cbmutableservice(type: transfer_service_uuid, primary: true)         // add characteristic         pmanager.addservice(transferservice)         pmanager.startadvertising(nil)     } } ... 

central.swift

... var cmanager = cbcentralmanager()  override func viewdidload() {     super.viewdidload()     cmanager = cbcentralmanager(delegate: self, queue: nil) }  func centralmanagerdidupdatestate(central: cbcentralmanager!) {     if central.state == cbcentralmanagerstate.poweredon {         cmanager.scanforperipheralswithservices([transfer_service_uuid], options: nil)     } } ... 

now, if take 2 device, 1 central , other peripheral role 2 app can't find each other (but lightblue app , similar will device emitting)

on other hand, if change code to:

cmanager.scanforperipheralswithservices(nil, options: nil) 

my application works , 2 devices can communicate each other.. @ same time can't filter devices emitting transfer_service_uuid.. don't want connect peripheral finded in order search transfer_service_uuid.. isn't right way proceed ?? did miss ??

there limited space in bluetooth advertisement area, ios not automatically advertise services - device may have primary service , several supplementary services. advertising services wasteful when required discover primary service in order identify candidate device.

to able discover service in scanforperipheralswithservices need include service in advertisement data.

this done including service's uuid in dictionary pass cbperipheralmanager.startadvertising -

pmanager.startadvertising([cbadvertisementdataserviceuuidskey:[transfer_service_uuid]]) 

Comments

Popular posts from this blog

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -