ios - why isn't the CBPeripheralManagerDelegate method calling? -
why isn't cbperipheralmanagerdelegate method callinga although have initialized class var bluetoothmanager = cbperipheralmanager(delegate: self, queue: nil, options: nil)
and added bluetooth framework in bundle.
import uikit import corebluetooth class appsettingsviewcontroller: uiviewcontroller { override func viewdidload() { super.viewdidload() var bluetoothmanager = cbperipheralmanager(delegate: self, queue: nil, options: nil) } override func didreceivememorywarning() { super.didreceivememorywarning() // dispose of resources can recreated. } } extension appsettingsviewcontroller : cbperipheralmanagerdelegate{ func peripheralmanagerdidupdatestate(peripheral: cbperipheralmanager!) { if peripheral.state == cbperipheralmanagerstate.poweredon{ println("broadcasting") }else if peripheral.state == cbperipheralmanagerstate.poweredoff{ println("no bluetooth found") }else if peripheral.state == cbperipheralmanagerstate.unauthorized { println("this option not allowed application") } } }
make bluetoothmanager
instance variable. gets deallocated when viewdidload()
finishes.