Не удается обнаружить iBeacon в iOS 8

Я следовал онлайн-учебникам от AppCoda и Devfright, чтобы создать приложение для обнаружения iBeacon. Я использую iBeacon от estimote, iPad 3 с iOS 8. Приложение просто не обнаруживает мой iBeacon, тогда как его обнаруживают другие приложения iBeacon. Я не могу понять, что я пропускаю или делаю неправильно в моем коде.

Вот мой файл.h:

#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>

@interface ViewController : UIViewController<CLLocationManagerDelegate>

@property (nonatomic, strong) CLBeaconRegion   *beaconRegion;
@property (nonatomic, strong) CLLocationManager *locManager;

@property (nonatomic, strong) IBOutlet UILabel *label1;
@property (nonatomic, strong) IBOutlet UILabel *label2;

@end

Вот мой файл.m:

#import "ViewController.h"
#import <CoreLocation/CoreLocation.h>

@interface ViewController () <CLLocationManagerDelegate>

@end

@implementation ViewController


- (void)viewDidLoad {
[super viewDidLoad];

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

//default uuid for estimote beacons
NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:@"B9407F30-F5F8-466E-AFF9-25556B57FE6D"];

self.beaconRegion = [[CLBeaconRegion alloc]initWithProximityUUID:uuid identifier:@"com.rk.testregion"];

[self.locManager startMonitoringForRegion:self.beaconRegion];
[self locationManager:self.locManager didStartMonitoringForRegion:self.beaconRegion];

// 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)locationManager:(CLLocationManager*)manager didRangeBeacons:(NSArray*)beacons inRegion:(CLBeaconRegion*)region
{
// Beacon found!
self.label1.text = @"Welcome to";
self.label2.text = @"Location 1";

CLBeacon *foundBeacon = [beacons firstObject];

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

NSLog(@"UUID: %@", uuid);
NSLog(@"major: %@", major);
NSLog(@"minor: %@", minor);

}

- (void)viewDidDisappear:(BOOL)animated
{
[self.locManager stopRangingBeaconsInRegion:self.beaconRegion];

[super viewDidDisappear:animated];
}

- (void)locationManager:(CLLocationManager*)manager didEnterRegion:(CLRegion*)region
{
[self.locManager startRangingBeaconsInRegion:self.beaconRegion];
}

-(void)locationManager:(CLLocationManager*)manager didExitRegion:(CLRegion*)region
{
[self.locManager stopRangingBeaconsInRegion:self.beaconRegion];
self.label1.text = @"Searching again...";
}

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

[self.locManager startRangingBeaconsInRegion:self.beaconRegion];
}

@end

Метод делегата didRangeBeacons просто не вызывается. Может кто-нибудь, пожалуйста, дайте мне знать, как это исправить.

1 ответ

Решение

Посмотрите ответ ниже, в котором описаны некоторые дополнительные обручи, через которые вам сейчас нужно перейти, чтобы это сработало:

Службы определения местоположения не работают в iOS 8

Полное раскрытие: я не пробовал это сам.

Другие вопросы по тегам