Xplorer
Xplorer

Reputation: 28

iBeacon Receiver is not recognising the transmitted signal

I am working on iBeacon transmitter and receiver. I have successfully completed the transmitter part but the other part the receiver is not recognising the transmitted signal. Can any body please help me identify where i went wrong? Is there anything more I have to add in .plist. I have tried stackoverflow answers but sorry to tell that nothing worked.

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    // Initialize location manager and set ourselves as the delegate
    self.locationManager = [[CLLocationManager alloc] init];
    self.locationManager.delegate = self;

    // Create a NSUUID with the same UUID as the broadcasting beacon
    NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:@"A77A1B68-49A7-4DBF-914C-760D07FBB87B"];

    // Setup a new region with that UUID and same identifier as the broadcasting beacon
    self.myBeaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid identifier:@"xx.xxxxxx.xxxxxxxx"];

    // Tell location manager to start monitoring for the beacon region
    [self.locationManager startMonitoringForRegion:self.myBeaconRegion];

    // Check if beacon monitoring is available for this device
    if (![CLLocationManager isMonitoringAvailableForClass:[CLBeaconRegion class]]) {

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Monitoring not available" message:nil delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles: nil];
        [alert show];
        return;
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)locationManager:(CLLocationManager*)manager didEnterRegion:(CLRegion *)region
{
    // We entered a region, now start looking for our target beacons!
    self.statusLabel.text = @"Finding beacons.";
    [self.locationManager startRangingBeaconsInRegion:self.myBeaconRegion];
}

-(void)locationManager:(CLLocationManager*)manager didExitRegion:(CLRegion *)region
{
    // Exited the region
    self.statusLabel.text = @"None found.";
    [self.locationManager stopRangingBeaconsInRegion:self.myBeaconRegion];
}

-(void)locationManager:(CLLocationManager*)manager
       didRangeBeacons:(NSArray*)beacons
              inRegion:(CLBeaconRegion*)region
{
    // Beacon found!
    self.statusLabel.text = @"Beacon found!";

    CLBeacon *foundBeacon = [beacons firstObject];

    // You can retrieve the beacon data from its properties
    //NSString *uuid = foundBeacon.proximityUUID.UUIDString;
    //NSString *major = [NSString stringWithFormat:@"%@", foundBeacon.major];
    //NSString *minor = [NSString stringWithFormat:@"%@", foundBeacon.minor];
}

@end

Upvotes: 0

Views: 153

Answers (3)

Abhinav
Abhinav

Reputation: 38142

Just a side thought to try and debug the issue (Although from your code everything seems to be written correctly).

First, lets see if you got some error while initialising your listener. To do that, lets implement these delegates and see if you get some error here:

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
- (void)locationManager:(CLLocationManager *)manager monitoringDidFailForRegion:(CLRegion *)region withError:(NSError *)error

Second, implement below delegate to check if location manager started monitoring your region. You can NSLog your region' UUID and identifier just to be doubly sure.

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

Next, if you get above call back then everything seems fine on your listener. Try couple of things now:

  1. Is your broadcaster is really broadcasting?
  2. If yes, is it broadcasting the same UUID your listener is expecting.
  3. If yes, try switching off listener and broadcaster. Reboot the device and then switch on broadcaster followed by listener.

I have experienced, Location management not work instantaneously. For instance, once you detected the region entry, if you got out of the region you may not get immediate call back and then if you enter the same region again without getting exit call, you will not receive entry call. I've seen #3, working in many situations.

Also, a tip that I am not remembering where I got from :). Start ranging your beacons along with monitoring. Sometimes this gives better results.

Upvotes: 0

r4id4
r4id4

Reputation: 6077

You need to ask the permission to use the bluetooth.

Use requestAlwaysAuthorization (for background location) or requestWhenInUseAuthorization (when foreground).

You also need the NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription key in Info.plist with a message to be displayed in the prompt to the user like "I need your permission to access bluetooth" or whatever.

Upvotes: 1

skyming
skyming

Reputation: 9

In previous system versions, it will automatically notify the user to authorize when the location service is being used. In iOS 8, Apple has updated the authorization strategy, which requires to call the function to request user's authorization. The corresponding SDK has also provided alternative function.

1.requestAlwaysAuthorization Firstly, the notification content is required. When calling the function, the system will push this paragraph of text to the user if he/she has not authorize the App to use the service. You may need to add the following key to Info.plist:

NSLocationAlwaysUsageDescription Meanwhile, a written desciption should be added, without which calling the function will be invalid. Secondly, call the authorization function.

[locationManger requestAlwaysAuthorization];

Upvotes: 0

Related Questions