我正在開發iPhone應用程序並已實施CBCentralManager
。還用後臺模式更新了plist,使用標識符初始化centralmanager。狀態保存和恢復BLE-調用didFinishLaunchingWithOptions,但不調用CBCentral的任何代理方法
而且已經在didFinishLaunchingWithOptions
if var centralManagerIdentifiers: NSArray = launchOptions? [UIApplicationLaunchOptionsBluetoothCentralsKey] as? NSArray {
// Awake as Bluetooth Central
// No further logic here, will be handled by centralManager willRestoreState
for identifier in centralManagerIdentifiers {
if identifier as NSString == "centralManager"{
var notification = UILocalNotification()
notification.alertBody = String(centralManagerIdentifiers.count)
notification.alertAction = "open"
notification.fireDate = NSDate()
notification.soundName = UILocalNotificationDefaultSoundName
UIApplication.sharedApplication().scheduleLocalNotification(notification)
}
}
}
我已經創造了不同的類中的中央管理器中添加該代碼,這是單身。
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"])
}
如果我不使用我的應用程序的一兩天,然後開始周邊廣告,應用程序喚醒和火災此通知,但不調用任何CBCentral委託方法。我也實現了willRestoreState方法,但那也沒有獲取卡。
使用案例:我需要連接外圍設備並在其開始廣告後發送數據,即使應用程序未被使用。 當應用程序獲取didFinishLaunchingWithOptions調用時,我應該在哪裏處理連接過程?我是否必須在did finishlaunch方法中初始化centralManager?
所以它第一次工作,當我打開它調用willRestoreState,didUpdateState,didConnectPeripherial的外設。 當我關閉外設時,它也調用了willRestoreState,如果我再打開它,除非我解鎖iPhone,否則不會執行任何操作。 – Paragon
這是一個不同的問題。看起來您沒有正確使用恢復流程。 –
當我關閉外圍設備時應該調用willRestoreState嗎? – Paragon