2

I have written a small iBeacon demo app that ranges for beacons and then will monitor for beacons in range after they have been found for the first time. After I run this app (if it's still in the background), I find that the device has trouble making new Bluetooth connections. When I enter my car, for instance, my car infinitely tries to connect to the phone with no success until I turn Bluetooth off and on again. This seems like an issue of keeping Bluetooth active after leaving the area of the iBeacons, but I have stopped ranging for beacons on didExitRegion. I have even attempted stopping ranging for beacons when the view disappears or when the app is closed. Is there some other step to take in order to properly close connections when leaving a range?

Edit: I only say ranging in the OP, but I have since also made sure to stop monitoring for beacon regions when the app goes inactive and when exiting regions. The problem persists

Edit 2: If I must say specific behavior expected, I expect to be able to range and monitor for beacons while the app is running and while it is in the background without stopping up other Bluetooth connections. The actual behavior is that it does keep track of beacons in these cases, but it doesn't allow other bluetooth connections to be formed.

Code to initialize and start monitoring for beacons (in viewDidLoad):

if (self.beaconManager == nil) {
    self.beaconManager = [[ESTBeaconManager alloc] init];
    self.beaconManager.delegate = self;
}
if (self.icyMarshmallowRegion == nil) {
    self.icyMarshmallowRegion = [[ESTBeaconRegion alloc] initWithProximityUUID:ESTIMOTE_PROXIMITY_UUID major:[kIcyMarshmallowMajor integerValue] minor:[kIcyMarshmallowMinor integerValue] identifier:kIcyMarshmallowRegionID];
    self.icyMarshmallowRegion.notifyOnEntry = YES;
    self.icyMarshmallowRegion.notifyEntryStateOnDisplay = YES;
}
[self.beaconManager startMonitoringForRegion:self.icyMarshmallowRegion];

Code to stop monitoring (in didExitRegion):

[self.beaconManager stopMonitoringForRegion:self.icyMarshmallowRegion];

1 Answers1

1

There is no more step to "close the Bluetooth activity", and anyway your device should be able to take other connections while monitoring for iBeacon regions (I'm not sure for ranging cause it's more an 'active' task, but I bet it's the same thing)

I've seen a lot of strange behaviour related to iBeacon in iOS7, part of them are fixed in iOS8, hopefully everything will be soon ok. I think you shouldn't worry about your code for the problem you describe, and wait for iOS8

Rishil Patel
  • 1,977
  • 3
  • 14
  • 30
Macistador
  • 854
  • 12
  • 23
  • seriously? he made a mistake -- chances are high. chances that ios8 fixes it are low – Daij-Djan Jul 24 '14 at 07:28
  • 1
    An app can't influence (or shouldn't be able) to prevent the OS to take other Bluetooth connection. If the problem was inside his app, chances that he made a mistake would be very high, but as we speak about outside the app this is a OS problem. And speaking about BLE, as I said, I've seen lately a lot of similar problems – Macistador Jul 24 '14 at 07:38
  • that convokes me -- it is not related to his app then – Daij-Djan Jul 24 '14 at 07:43
  • For example, when you exit an iBeacon region and enter inside again, IOS7 would sometimes not detect it for a while, IOS8 has fixed that. Another example is the famous KCLErrorDomain 16 (see http://stackoverflow.com/questions/20905843/locationmanagerrangingbeaconsdidfailforregionwitherror-kclerrordomain-16 or http://stackoverflow.com/questions/22946022/ibeacon-didrangebeacons-stops-getting-called-must-reset-device-for-it-to-work/22949187#22949187) – Macistador Jul 24 '14 at 07:47
  • @Macistador It must be related to the app in some way, as this problem only occurs after having that specific app run. Though, that is a very good point that a single app shouldn't have the capacity to take down the entire OS's ability to connect to Bluetooth devices just by monitoring or ranging for beacons. That is built in functionality that Apple wouldn't want to have the ability to control the whole system. I'll see if iOS 8 fixes the problem as soon as I have a device I can put it on, thanks for the tip. Daij-Djan: I probably did mess up, if you have any idea where please let me know. – kristianfpc Jul 24 '14 at 16:10
  • I am pretty sure your application triggers the bluetooth problem, but without necessarily doing something wrong. Did you try to remove all the monitorized regions ? It could potentially ease the detection... – Macistador Jul 24 '14 at 16:32
  • @Macistador I'm not exactly sure what you mean by that. I have stopped monitoring for regions when I exit them and when the app closes. I start monitoring for them when I enter them and when the app opens. Is this overzealous? – kristianfpc Jul 24 '14 at 17:10
  • To be sure you can do something like : for (CLBeaconRegion *region in self.locationManager.rangedRegions) { [self.locationManager stopRangingBeaconsInRegion:region]; } for (CLRegion *region in self.locationManager.monitoredRegions) { [self.locationManager stopMonitoringForRegion:region]; } – Macistador Jul 24 '14 at 17:22
  • @Macistador very thorough, I'll give it a shot. When do you recommend that that happens? As I have it now, it will happen when the app opens and closes. Should it also happen when exiting a region? I wouldn't think so, since the user has only exited one region, but it could be the solution. – kristianfpc Jul 24 '14 at 17:48
  • It depends on what behaviour you are looking for; first of all you can try this (anywhere) just to check if it helps – Macistador Jul 24 '14 at 17:52
  • @Macistador The code worked like a charm. It fixed the issues Bluetooth had with connecting. Obviously, it stopped monitoring regions that I wanted monitored, but I just added one line after the two loops to start monitoring for just one region and it does monitor properly in the background while still connecting to other Bluetooth devices. Thanks so much! It is concerning, though, that monitoring and ranging for regions could potentially cause Bluetooth issues – kristianfpc Jul 25 '14 at 18:32