I've a custom class (let's say, MyBLE
) that served as a CoreBluetooth
wrapper (similar to LGBluetooth, I guess). It handles communications between my BLE accessory and the iOS device:
MyBLE.h
@interface MyBLE : NSObject
@property (nonatomic, strong) CBCentralManager *central;
@property (nonatomic, strong) CBPeripheral *peripheral;
+ (MyBLE *)sharedInstance;
//...
@end
In the AppDelegate
, I initialized it as a MyBLE
object, which works fine in the foreground. I set up the needed entries in the Info.plist to use the UIBackgroundMode
according to Core Bluetooth Programming Guide so I can kept getting data send by the BLE accessory.
But when I pressed the home button, Xcode console no longer print out any message that should be printed when the iOS got data from the BLE peripheral. The device is already connected to iOS device (central) before went into background mode.
Did I miss anything? It seems that the app no longer gets data from BLE device after 3 mins. (Yes, I did add the bluetooth-central
)
After I moved the initialization of MyBLE
object from -init:
to -application:didFinishLaunchingWithOptions:
, it worked.
Guess somehow the delegate wasn't considered initialized at that point.