Objective c (Kontakt.io)iBeacon未点火

Objective c (Kontakt.io)iBeacon未点火,objective-c,ios7,ibeacon,Objective C,Ios7,Ibeacon,我有三个全新的Kontakt.io信标,用它和我的iPhone4S尝试识别它们。我所做的只是更改UUID(所有Kontakt.io信标从一开始就具有相同的UUID)并添加一些代码: 这一行应该强制应用程序检查它是否已经在该地区 [self.locationManager requestStateForRegion:self.myBeaconRegion]; 这些线路用于检查系统的设置是否正确: NSArray *locationServicesAuthStatuses = @[@"Not de

我有三个全新的Kontakt.io信标,用它和我的iPhone4S尝试识别它们。我所做的只是更改UUID(所有Kontakt.io信标从一开始就具有相同的UUID)并添加一些代码:

这一行应该强制应用程序检查它是否已经在该地区

[self.locationManager requestStateForRegion:self.myBeaconRegion];
这些线路用于检查系统的设置是否正确:

NSArray *locationServicesAuthStatuses = @[@"Not determined",@"Restricted",@"Denied",@"Authorized"];
NSArray *backgroundRefreshAuthStatuses = @[@"Restricted",@"Denied",@"Available"];

BOOL monitoringAvailable = [CLLocationManager isMonitoringAvailableForClass:[self.myBeaconRegion class]];
NSLog(@"Monitoring available: %@", [NSNumber numberWithBool:monitoringAvailable]);

int lsAuth = (int)[CLLocationManager authorizationStatus];
NSLog(@"Location services authorization status: %@", [locationServicesAuthStatuses objectAtIndex:lsAuth]);

int brAuth = (int)[[UIApplication sharedApplication] backgroundRefreshStatus];
NSLog(@"Background refresh authorization status: %@", [backgroundRefreshAuthStatuses objectAtIndex:brAuth]);
当我启动应用程序时,手机旁边的iBeacons不会启动。另外,当我取出电池并把它们放回(模拟出射程外又回到射程内)时,什么也没发生。当我使用真正的iBeacons时,其他Github示例代码也不适用于我,只有当我使用另一台iPhone传输信号时

这是ViewController。h:

- (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];

// Force app to check if it's already IN the region
[self.locationManager requestStateForRegion: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;
}

NSArray *locationServicesAuthStatuses = @[@"Not determined",@"Restricted",@"Denied",@"Authorized"];
NSArray *backgroundRefreshAuthStatuses = @[@"Restricted",@"Denied",@"Available"];

BOOL monitoringAvailable = [CLLocationManager isMonitoringAvailableForClass:[self.myBeaconRegion class]];
NSLog(@"Monitoring available: %@", [NSNumber numberWithBool:monitoringAvailable]);

int lsAuth = (int)[CLLocationManager authorizationStatus];
NSLog(@"Location services authorization status: %@", [locationServicesAuthStatuses objectAtIndex:lsAuth]);

int brAuth = (int)[[UIApplication sharedApplication] backgroundRefreshStatus];
NSLog(@"Background refresh authorization status: %@", [backgroundRefreshAuthStatuses objectAtIndex:brAuth]);
}

- (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];
}
这是NSLog输出:

2014-05-29 00:49:19.951 BeaconReceiver[2803:60b] Monitoring available: 1
2014-05-29 00:49:19.967 BeaconReceiver[2803:60b] Location services authorization status: Authorized
2014-05-29 00:49:20.109 BeaconReceiver[2803:60b] Background refresh authorization status: Available

非常感谢你的帮助

首先,请验证您是否可以使用现成的应用程序(如Locate for iBeacon)检测您的信标,该应用程序可在此处找到:。它将验证信标是否正常工作,UUID是否配置为您所期望的

一旦您确定信标与您的设备一起工作,然后开始对代码进行故障排除


编辑:在测试之前,请确保重新启动手机,以防出现已知的iOS 7.1错误;:

我忘了提到我显然检查了Kontakt.io应用程序,它立即识别了信标。但是,我尝试使用“Locate for iBeacon”并输入了上面提到的UUID,但没有显示任何结果。我还有一个Estimote信标,我在“为iBeacon定位”应用程序中找不到它,尽管它们的UUID也是标准化的。然而,当我尝试时,所有信标都完美地显示出来,但应用程序只显示蓝牙服务UUID,而不显示iBeacon接近UUID。所以我的手机理论上可以找到它,我是iBeacon定位的作者,所以我可以告诉你,这个应用程序是一个围绕CoreLocation API的非常简单的包装器。如果您没有看到该应用程序中的信标,我强烈怀疑正在传输的UUID未配置。如果您认为有可能您没有正确的UUID,您可以在Android上尝试相同的应用程序(如果您有Android设备)或我们针对Mac的Scanbacon产品,因为它们允许在不输入匹配UUID的情况下检测iBeacons。最后一点注意:请看我关于重新启动的编辑。哇,似乎是iOS 7.1的错误,重新启动后效果很好。非常感谢。