我是艾哈迈德。3 天来,我一直在尝试解决一个关于第一次与 Estimote 信标通信的问题。(我对信标很陌生),我阅读了很多文章并寻找了许多示例代码。甚至尝试了 Estimote 示例应用程序(在 Estimote SDK 文件中提供)。有些我无法通过我编写的代码和 SDK 文件中的示例代码(应用程序)找到信标。但是应用商店上的 estimote 应用程序运行良好。
我正在使用 MacBookPro 2011 年末版本。
如果您对此提供帮助,我将不胜感激。我的目的是先沟通,然后剩下的会来。我不能从房子里出去,所以我就这样写了代码。
这是我正在使用的代码。
//MainViewController.h
@interface MainViewController : UIViewController<CLLocationManagerDelegate>
@property(nonatomic, strong)CLBeaconRegion *beaconRegion;
@property(nonatomic, strong)CLLocationManager *locationManager;
@end
@implementation MainViewController
(void)viewDidLoad
{
[super viewDidLoad];
self.locationManager = [[CLLocationManager alloc]init];
self.locationManager.delegate = self;
[self initRegion];
[self locationManager:self.locationManager didStartMonitoringForRegion:self.beaconRegion];
}
- (void)locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region {
NSLog(@"did start monitoring");
[self.locationManager startRangingBeaconsInRegion:self.beaconRegion];
}
-(void)initRegion
{
NSLog(@"Init Region");
NSUUID *uuid = [[NSUUID alloc]initWithUUIDString:@"B9407F30-F5F8-466E-AFF9-25556B57FE6D"];
self.beaconRegion = [[CLBeaconRegion alloc]initWithProximityUUID:uuid identifier:@"identifier"] ;
[self.locationManager startMonitoringForRegion:self.beaconRegion];
}
-(void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
NSLog(@"Did enter region"); // never called
[self.locationManager startRangingBeaconsInRegion:self.beaconRegion];
}
-(void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region
{
NSLog(@"Did exit region"); // never called
[self.locationManager stopRangingBeaconsInRegion:self.beaconRegion];
NSLog(@"NO Beacon Found...");
}
-(void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region
{
NSLog(@"did range Beacons");
CLBeacon *beacon = [[CLBeacon alloc]init];
beacon = [beacons lastObject];
NSLog(@"BEACON FOUND");
NSLog(@"Proximity UUID: %@",beacon.proximityUUID.UUIDString);
NSLog(@"MAJOR ID: %@", beacon.major);
NSLog(@"MINOR ID: %@", beacon.minor);
}
@end