swift - State Preservation and Restoration BLE- Calls didFinishLaunchingWithOptions but doesn't call any delegate method for CBCentral -


i working on iphone app , have implemented cbcentralmanager. updated plist background modes, initialized centralmanager identifier.

also have added code in didfinishlaunchingwithoptions

if var centralmanageridentifiers: nsarray = launchoptions?    [uiapplicationlaunchoptionsbluetoothcentralskey] as? nsarray {     // awake bluetooth central     // no further logic here, handled centralmanager willrestorestate      identifier in  centralmanageridentifiers {         if identifier nsstring == "centralmanager"{             var notification = uilocalnotification()             notification.alertbody = string(centralmanageridentifiers.count)              notification.alertaction = "open"              notification.firedate =  nsdate()             notification.soundname = uilocalnotificationdefaultsoundname              uiapplication.sharedapplication().schedulelocalnotification(notification)              }         } } 

i have created central manager in different class , singleton.

    class var sharedinstance: blemanager {     struct singleton {         static let instance = blemanager()     }      return singleton.instance }   override init() {     super.init()     let centralqueue = dispatch_queue_create(“centralmanager_queue”, dispatch_queue_serial)     centralmanager = cbcentralmanager(delegate: self, queue: centralqueue, options: [cbcentralmanageroptionrestoreidentifierkey : "centralmanager"]) } 

if don't use app day or 2 , peripheral starts advertising, app wakes , fires notification doesn't call cbcentral delegate method. have implemented willrestorestate method thats not getting card.

use case: need connect peripheral , send data once starts advertising, though app not being used. should handle connection process when app gets didfinishlaunchingwithoptions call? have initialize centralmanager in did finishlaunch method?

the central manager must initialized handle delegate call. delegate method gets called once cbperipheralmanager created , delegate passed init method. if identifier of manager matches pending session state restored.

a point instantiate manager in didfinishlaunchingwithoptions method.

you can test easy causing crash, or pressing stop button of xcode while testing, , waiting new action triggered ble (a notification notifying characteristic example). it's faster waiting few days system kills app inactivity.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -