iBeacon接收器应用程序无法正常工作

时间:2014-12-26 13:49:53

标签: ios iphone ibeacon

提前致谢

我有ie的IBeacon Broadcaster和接收器示例应用程序。但Ibeacon接收器不能在某些设备上工作。 这是我的代码

enter code here- (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:@"com.appcoda.testregion"];

// 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)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];}

但这些代码在某些设备中有效

1 个答案:

答案 0 :(得分:0)

1)您在验证监控可用之前尝试进行监控。

2)我没有看到任何授权请求:

locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.requestAlwaysAuthorization()

3)要获得甚至工作的授权,你需要在你的plist中有一个字符串:     NSLocationAlwaysUsageDescription

如果你google周围使用" CLLocationManager requestAlwaysAuthorization NSLocationAlwaysUsageDescription"你会发现许多博客都有关于如何让信标跟踪工作的分步说明。