Search code examples
ioscore-bluetoothibeacon

ibeacon will not work


In the info.plist :

We have added the NSLocationAlwaysUsageDescription. On required background modes we have added ALL the bluetooth stuff( communicate and share data with bluetooth) and the location - "register for location updates"

We have imported the location and bluetooth frameworks ,and foundation.

We are starting the bluetooth with this :

  if([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)])
    {
        [self.locationManager requestAlwaysAuthorization];
     }



    self.locationManager = [[CLLocationManager alloc] init];
    self.locationManager.delegate = self;



    self.beaconRegion.notifyOnEntry=YES;
    self.beaconRegion.notifyOnExit=YES;
    self.beaconRegion.notifyEntryStateOnDisplay=YES;
    [self.locationManager requestAlwaysAuthorization ];
    [self.locationManager requestWhenInUseAuthorization];



    NSUUID *uuid_in = [[NSUUID alloc] initWithUUIDString:uuid];
    self.beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid_in identifier:@"com.name.us"];
    [self.locationManager startMonitoringForRegion:self.beaconRegion];

The delegate is called :

- (void)locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region {

    NSLog(@"started:%@",region);
    //[self.locationManager requestStateForRegion:self.beaconRegion];

    self.beaconRegion.notifyEntryStateOnDisplay=YES;

}

Problem is that when we turn on the hardware beacon(which is working-checked with other apps) the delegates are not being called (iPhone6):

- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
-(void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region {
-(void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region {

Solution

  • A few tips:

    1. You should only do one of these two. Get rid of the second line if you have the first line. (You also have the same first line repeated above.)

      [self.locationManager requestAlwaysAuthorization ]; [self.locationManager requestWhenInUseAuthorization];

    2. No special background modes are needed.

    3. Bluetooth framework is not needed.

    4. You are modifying your CLBeaconRegion before it is initialized. The lines starting with self.beaconRegion.notifyOnEntry=YES; need to be moved down to be after initialization.

    5. Make sure the ProximityUUID defined in uuid_in actually matches your beacon. Please post the code of how this is initialized so we can help be sure.

    6. Try uninstalling and reinstalling your app. Make sure you get prompted for location permissions on first launch and accept. If you do not get prompted, something is wrong.