core bluetooth - CoreBluetooth State Preservation and Restoration -


i have following scenario: ios app (peripheral) x osx app (central)

  • i instantiate peripheral manager cbperipheralmanageroptionrestoreidentifierkey.
  • in peripheral's didfinishlaunchingwithoptions send local notification after getting peripheral uiapplicationlaunchoptionsbluetoothperipheralskey (don't it)
  • in peripheral's willrestorestate trigger notification (don't other that)

if peripheral app still running in background before gets killed due memory pressure, messages osx central fine.

after ios app gets killed, when osx central sends message, both notifications mentioned above come through on ios, message expecting doens't.

i've not resintantiated peripheralmanager @ moment, , how should it? have 1 peripheralmanager entire cycle of app.

any suggestions welcome.

update:

if do

let options: dictionary = [cbperipheralmanageroptionrestoreidentifierkey: "myid"] peripheralmanager = cbperipheralmanager(delegate: self, queue: nil, options: options) 

in willrestorestate, apps lose connection

right, after having re-viseted topics on matter 100 times i've figured out, here how should implemented:

in appdelegate's didfinishlaunchingwithoptions:

if let options = launchoptions {     if let peripheralmanageridentifiers: nsarray = options[uiapplicationlaunchoptionsbluetoothperipheralskey] as? nsarray {          //loop through peripheralmanageridentifiers reinstantiating each of peripheralmanagers         //cbperipheralmanager(delegate: corebluetooth, queue: nil, options: [cbperipheralmanageroptionrestoreidentifierkey: "identifierinarray"])      }     else {         //there no peripheralmanagers reinstantiated, instantiate them     } } else {     //there nothing in launchoptions, instantiate them } 

at point, willrestorestate should start getting called, however, there no centrals in array of centrals if have 1 manage centrals subscribed characteristics. since centrals subscribed of characteristics in 1 single service have, loop though subscribedcentrals in of characteristics re-adding them array of centrals.

please modify according needs.

in willrestorestate:

var services = dict[cbperipheralmanagerrestoredstateserviceskey] as! [cbmutableservice]  if let service = services.first {      if let characteristic = service.characteristics?.first as? cbmutablecharacteristic {          subscribedcentral in characteristic.subscribedcentrals! {             self.cbcentrals.append(subscribedcentral as! cbcentral)         }      }  } 

after should ok call methods have prepared talk central, if deal several of them simultaneously.

good luck!


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -