1

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)

Cai
  • 3,609
  • 2
  • 19
  • 39
  • 1
    Is the peripheral updating the data and sending `notify` or are you issuing a polling read? Did you get prompted for background Bluetooth permission when you first ran the app? – Paulw11 Jul 20 '16 at 19:47
  • No I didn't notice a "background Bluetooth permission". (I thought only the background GPS tracking permission has such thing.) The peripheral is sending data to the central (iOS) in this case. It worked in the foreground, but no console log when in background. I can't verify if it's working correctly or not. Or it's normal that it has not console log in background? (which, would be strange.) – Cai Jul 20 '16 at 22:54

1 Answers1

1

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.

Cai
  • 3,609
  • 2
  • 19
  • 39