ios - Core Bluetooth State Restoration -


i working on app reacts on disconnects of peripherals , trying adopt ne state preservation , restoration introduced in ios 7.

i did documentation says, means:

  1. i added background mode centrals.

  2. i instantiate central manager same unique identifier.

  3. i implemented centralmanager:willrestorestate: method.

when app moves background kill in appdelegate callback kill(getpid(), sigkill);. (core bluetooth state preservation , restoration not working, can't relaunch app background)

when disconnect peripheral removing battery app being waked expected , launchoptions[uiapplicationlaunchoptionsbluetoothcentralskey] contains correct identifier centralmanager:willrestorestate: not called. if disconnect peripheral method gets called.

this how have it:

- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions  {      nsarray *peripheralmanageridentifiers = launchoptions[uiapplicationlaunchoptionsbluetoothperipheralskey];      if (peripheralmanageridentifiers) {          // we've restored, create _manager on main queue         _manager = [[cbperipheralmanager alloc] initwithdelegate:self                                                           queue:dispatch_get_global_queue(dispatch_queue_priority_default, 0)                                                         options:@{cbperipheralmanageroptionrestoreidentifierkey:@"youruniqueidentifier"}];      } else {          // not restored create normal         manager = [[cbperipheralmanager alloc] initwithdelegate:self                                                           queue:nil                                                         options:@{cbperipheralmanageroptionrestoreidentifierkey:@"youruniqueidentifier"}];      } return yes; } 

and then:

- (void)peripheralmanager:(cbperipheralmanager *)peripheral          willrestorestate:(nsdictionary *)dict {       // advertisement data being advertised when app terminated ios     _advertisementdata = dict[cbperipheralmanagerrestoredstateadvertisementdatakey];      nsarray *services = dict[cbperipheralmanagerrestoredstateserviceskey];      // loop through services, have 1 service if have more you'll need check against uuid strings of each     (cbmutableservice *service in services) {          _primaryservice = service;          // loop through characteristics         (cbmutablecharacteristic *characteristic in _primaryservice.characteristics) {              if ([characteristic.uuid.uuidstring isequaltostring:characteristic_uuid]) {                  _primarycharacteristic = characteristic;                  nsarray *subscribedcentrals = characteristic.subscribedcentrals;                  // loop through centrals subscribed when app terminated ios                 (cbcentral *central in subscribedcentrals) {                      // add them array                     [_centrals addobject:central];                  }             }         }     } } 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -