Curnelious
Curnelious

Reputation: 1

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 {

Upvotes: 0

Views: 93

Answers (2)

davidgyoung
davidgyoung

Reputation: 64941

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.

Upvotes: 2

Dan Loughney
Dan Loughney

Reputation: 4677

Couple things to check:

In privacy settings be sure that your app is checked to Allow Location Access. I'm not certain what will happen when you call both of these in your code:

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

Confirm UUID are you passing to initWithProximityUUID. This will need to match the beacons you are interested in finding.

Add monitoringDidFailForRegion to your code and see what you get...

(void)locationManager:(CLLocationManager *)manager monitoringDidFailForRegion:(CLRegion *)region withError:(NSError *)error {
    NSLog(error);
}

Upvotes: 1

Related Questions