-->

Receive BluetoothManager notifications in backgrou

2019-05-28 22:51发布

问题:

I'm using the BluetoothManager private framework in my app and I want to know how can I receive BluetoothManager notifications when the application is in background (ex: Receive the connected/disconected bluetooth notification in background).

Thanks in advance.

回答1:

Use

// global notification explorer
CFNotificationCenterAddObserver(CFNotificationCenterGetLocalCenter(),
    NULL, MyCallBack, NULL, NULL, 
    CFNotificationSuspensionBehaviorDeliverImmediately);

and receive the notifications:

// global notification callback
void MyCallBack (CFNotificationCenterRef center,void *observer,CFStringRef name,const void object,CFDictionaryRef userInfo)
{
    NSLog(@"CallBack:CFN Name:%@ Data:%@", name, userInfo);
}