Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CBCentralManager changes for iOS 7

I am trying to use Apple's 'BTLE Transfer' sample project to understand CoreBluetooth programming. The app runs fine if I use an iOS 6 device as the Central, but if I run the same app with the iOS 7 device as the Central it doesn't work. The peripheral stops sending after two packets, and the central doesn't receive either one of them.

The only clue is this warning that I get only when running on iOS 7:

CoreBluetooth[WARNING] <CBCentralManager: 0x15654540> is disabling duplicate filtering, but is using the default queue (main thread) for delegate events

Can anyone tell me what needs to change to make this app compatible with iOS 7?

EDIT: When both devices are iOS7 there are no issues. This only breaks when an iOS7 central is talking to a iOS6 peripheral.

like image 287
Drew C Avatar asked Sep 23 '13 22:09

Drew C


2 Answers

Okay I just ran it on an iOS 7 central to iOS 6 peripheral. If you want to make that warning about disabling duplicate filtering go away, just run it on a different thread. Do something like this:

dispatch_queue_t centralQueue = dispatch_queue_create("com.yo.mycentral", DISPATCH_QUEUE_SERIAL);// or however you want to create your dispatch_queue_t
_centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:centralQueue];

Now it will allow you to scan with duplicates enabled. However, you must call the textView setter on the main thread to be able to set the text without crashing:

dispatch_async(dispatch_get_main_queue(), ^{
    [self.textview setText:[[NSString alloc] initWithData:self.data encoding:NSUTF8StringEncoding]];
        });

Btw you probably also want to adopt the new iOS 7 delegate initialization:

_centralManager = [[CBCentralManager alloc]initWithDelegate:self queue:centralQueue options:nil];//set the restoration options if you want

(Just check the iOS version and call the appropriate initialization method)

like image 56
Tommy Devoy Avatar answered Sep 23 '22 20:09

Tommy Devoy


InscanForPeripheralsWithServices:options:,if you set CBCentralManagerScanOptionAllowDuplicatesKey:@YES then change it to CBCentralManagerScanOptionAllowDuplicatesKey:@NOthat means scan should run without duplicate filtering.

For me,it works on iOS7 also.

like image 38
manojdeshmane99 Avatar answered Sep 20 '22 20:09

manojdeshmane99