在iOS 8中无法检测到iBeacon

 菲菲鱼2009 发布于 2023-01-08 14:20

我已经跟随AppCoda和Devfright的在线教程创建了一个iBeacon检测应用程序.我正在使用来自estimote的iBeacon,这是一款支持iOS 8的iPad 3.该应用程序根本无法检测到我的iBeacon,而其他iBeacon应用程序正在检测它.我无法理解我在代码中遗漏或做错了什么.

这是我的.h文件:

#import 
#import 

@interface ViewController : UIViewController

@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 

@interface ViewController () 

@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中不起作用

    完全披露:我自己没试过.

    2023-01-08 14:23 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有