ios - iBeacon 接收器无法识别传输的信号

标签 ios iphone xcode xcode5 ibeacon

我正在研究 iBeacon 发射器和接收器。我已成功完成发射器部分,但接收器的另一部分无法识别传输的信号。任何人都可以帮我确定我哪里出了问题吗?我还需要在 .plist 中添加什么吗?我已经尝试过 stackoverflow 的答案,但遗憾的是没有任何效果。

#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

最佳答案

您需要请求许可才能使用蓝牙。

使用 requestAlwaysAuthorization(对于后台位置)或 requestWhenInUseAuthorization(对于前台)。

您还需要 Info.plist 中的 NSLocationAlwaysUsageDescriptionNSLocationWhenInUseUsageDescription 键,并在提示中向用户显示一条消息,例如“我需要您的权限才能访问蓝牙” “管他呢。

关于ios - iBeacon 接收器无法识别传输的信号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32710335/

相关文章:

ios - 如何操作 UITableView 根据表头编辑单元格?

ios - 避免 AppDelegate 中出现 "uncaughtExceptionHandler"警告

iphone - 防止objc block 复制属性

iphone - 用描边和填充颜色画圆

iphone - 将 NSManagedObject 存储在字典中 (NSDictionary)

iphone - UIimagepicker Controller 仅选择图像

swift - Facebook、Swift 3、FBSDK 中的授权

ios - ios中的图像翻译

ios - 图像未在 iPhone 设备上显示

iphone - 标签栏 Controller 和标签栏有什么区别?