Objective c 信标未呼叫区域中的信标
几个月前,我的代码运行良好。我什么都不知道 我不明白为什么当我启动我的应用程序时,区域内的DidRange信标不会触发:Objective c 信标未呼叫区域中的信标,objective-c,xcode,ibeacon,estimote,Objective C,Xcode,Ibeacon,Estimote,几个月前,我的代码运行良好。我什么都不知道 我不明白为什么当我启动我的应用程序时,区域内的DidRange信标不会触发: #import "ESTViewController.h" #import "PresentViewController.h" #import <ESTBeaconManager.h> #import <Parse/Parse.h> #import <AudioToolbox/AudioToolbox.h> @interface ESTV
#import "ESTViewController.h"
#import "PresentViewController.h"
#import <ESTBeaconManager.h>
#import <Parse/Parse.h>
#import <AudioToolbox/AudioToolbox.h>
@interface ESTViewController () <ESTBeaconManagerDelegate>
@property (nonatomic, strong) ESTBeaconManager* beaconManager;
@property (nonatomic, strong) ESTBeacon* selectedBeacon;
@property (nonatomic, strong) NSArray *beaconsArray;
@end
@implementation ESTViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// setup Estimote beacon manager.
// Create the manager instance.
self.beaconManager = [[ESTBeaconManager alloc] init];
// Setup the delegate
self.beaconManager.delegate = self;
// Avoiding unknown state or not
self.beaconManager.avoidUnknownStateBeacons = NO;
// create sample region object (beacons in this case have all same uuid and same major)
region = [[ESTBeaconRegion alloc] initWithProximityUUID:ESTIMOTE_PROXIMITY_UUID identifier:@"multibeacons"];
[self.beaconManager requestStateForRegion:region];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
// start looking for estimote beacons in region
// when beacon ranged beaconManager:didRangeBeacons:inRegion: invoked
[self.beaconManager startRangingBeaconsInRegion:region];
[self.beaconManager startMonitoringForRegion:region];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
// stop looking for estimote beacons in region
[self.beaconManager stopRangingBeaconsInRegion:region];
[self.beaconManager stopMonitoringForRegion:region];
}
#pragma mark - ESTBeaconManager delegate
-(void)beaconManager:(ESTBeaconManager *)manager
didRangeBeacons:(NSArray *)beacons
inRegion:(ESTBeaconRegion *)region
{
// descriptor on distance to sort the array of beacons by distance
NSSortDescriptor *sortDescriptor;
sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"distance" ascending:YES];
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
// sorting the array of beacons
// beacon array is sorted based on distance
// closest beacon is the first one
self.beaconsArray = [beacons sortedArrayUsingDescriptors:sortDescriptors];
if([self.beaconsArray count] > 0)
{
if(!self.selectedBeacon)
{
// initialy pick closest beacon
self.selectedBeacon = [beacons objectAtIndex:0];
currentBeaconMinor = self.selectedBeacon.minor;
}
else
{
//sorting the array of beacons
self.beaconsArray = [beacons sortedArrayUsingDescriptors:sortDescriptors];
//updating the selected beacon with the first element of the array (closest beacon)
if(self.selectedBeacon != [beacons objectAtIndex:0] )
{
self.selectedBeacon = [beacons objectAtIndex:0];
currentBeaconMinor = self.selectedBeacon.minor;
}
}
// Switch on proximity of the closest beacon
switch (self.selectedBeacon.proximity)
{
case CLProximityUnknown:
{
self.rangeStatusImageView.image = [UIImage imageNamed:@"lost.jpg"];
self.rangeStatusImageView.hidden = NO;
self.signalStatusImageView.hidden = YES;
self.descriptionStateLabel.text = @"Recherche de signal ... Si le problème persiste, contactez l'accueil";
[UIView animateWithDuration:1.0
delay: 0.0
options: UIViewAnimationOptionCurveEaseIn
animations:^{
self.rangeStatusImageView.alpha = 0.3;
}
completion:^(BOOL finished){
[UIView animateWithDuration:1.0
delay: 0.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
self.rangeStatusImageView.alpha = 1.0;
}
completion:nil];
}];
break;
}
case CLProximityImmediate:
{
if ([currentBeaconMinor floatValue] == 128)
{
NSLog(@"128 128 128");
[self performSegueWithIdentifier: @"presentSegue1" sender: self];
}
else if ([currentBeaconMinor floatValue] == 228)
{
NSLog(@"228 228 228");
[self performSegueWithIdentifier: @"presentSegue2" sender: self];
}
else if ([currentBeaconMinor floatValue] == 328)
{
NSLog(@"328 328 328");
[self performSegueWithIdentifier: @"presentSegue3" sender: self];
}
break;
}
case CLProximityNear:
{
self.rangeStatusImageView.image = [UIImage imageNamed:@"near.jpg"];
self.signalStatusImageView.hidden = NO;
AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
[UIView animateWithDuration:1.0
delay: 0.0
options: UIViewAnimationOptionCurveEaseIn
animations:^{
self.rangeStatusImageView.alpha = 0.3;
}
completion:^(BOOL finished){
[UIView animateWithDuration:1.0
delay: 0.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
self.rangeStatusImageView.alpha = 1.0;
}
completion:nil];
}];
self.rangeStatusImageView.hidden = NO;
self.descriptionStateLabel.font = [UIFont systemFontOfSize:17];
self.descriptionStateLabel.text = @"Approchez vous d'un article pour obtenir plus d'informations";
break;
}
case CLProximityFar:
{
self.rangeStatusImageView.image = [UIImage imageNamed:@"far.jpg"];
[self.rangeStatusImageView stopAnimating];
self.rangeStatusImageView.hidden = NO;
self.signalStatusImageView.hidden = NO;
self.descriptionStateLabel.text = @"Bienvenue dans notre ... ";
break;
}
default:
break;
}
self.beaconsArray = [beacons sortedArrayUsingDescriptors:sortDescriptors];
}
}
#导入“ESTViewController.h”
#导入“PresentViewController.h”
#进口
#进口
#进口
@接口ESTViewController()
@属性(非原子,强)ESTBeaconManager*beaconManager;
@属性(非原子,强)ESTBeacon*selectedBeacon;
@属性(非原子,强)NSArray*beaconsArray;
@结束
@视图控制器的实现
-(无效)viewDidLoad
{
[超级视图下载];
//设置远程信标管理器。
//创建管理器实例。
self.beaconManager=[[ESTBeaconManager alloc]init];
//设置代理
self.beaconManager.delegate=self;
//是否避免未知状态
self.beaconManager.avoidUnknownStateBeacons=否;
//创建示例区域对象(本例中的信标具有所有相同的uuid和相同的主节点)
region=[[ESTBeaconRegion alloc]initWithProximityUID:EstRemote_PROXIMITY_UUID标识符:@“多信标”];
[self.beaconManager requestStateForRegion:region];
}
-(无效)视图将显示:(BOOL)动画
{
[超级视图将显示:动画];
}
-(无效)视图显示:(BOOL)动画
{
[超级视图显示:动画];
//开始在该地区寻找estimote信标
//当信标范围为beaconManager:didRangeBeacons:inRegion:调用时
[self.beaconManager startrangingbeaconregion:region];
[self.beaconManager startMonitoringForRegion:region];
}
-(无效)视图将消失:(BOOL)已设置动画
{
[超级视图将消失:动画];
}
-(无效)视图消失:(BOOL)已设置动画
{
[超级视窗消失:动画];
//停止在该地区寻找estimote信标
[self.beaconManager stoprangingbeaconregion:region];
[self.beaconManager停止监视区域:区域];
}
#pragma标记-ESTBeaconManager代表
-(无效)beaconManager:(ESTBeaconManager*)经理
DidRange信标:(NSArray*)信标
区域:(ESTBEACON区域*)区域
{
//距离描述符,用于按距离对信标阵列进行排序
NSSortDescriptor*sortDescriptor;
sortDescriptor=[[NSSortDescriptor alloc]initWithKey:@“距离”递增:是];
NSArray*sortDescriptors=[NSArray数组带对象:sortDescriptor];
//对信标阵列进行排序
//信标阵列根据距离进行排序
//最近的信标是第一个
self.beaconsArray=[beacons SortedArray使用描述符:sortDescriptors];
如果([self.beaconsArray count]>0)
{
如果(!self.selectedBeacon)
{
//初始选择最近的信标
self.selectedBeacon=[beacons对象索引:0];
currentBeaconMinor=self.selectedBeacon.minor;
}
其他的
{
//对信标阵列进行排序
self.beaconsArray=[beacons SortedArray使用描述符:sortDescriptors];
//使用阵列的第一个元素(最近的信标)更新所选信标
if(self.selectedBeacon!=[beacons objectAtIndex:0])
{
self.selectedBeacon=[beacons对象索引:0];
currentBeaconMinor=self.selectedBeacon.minor;
}
}
//打开最近信标的接近开关
开关(自选信标接近)
{
案例CLP未知:
{
self.rangeStatusImageView.image=[UIImage ImageName:@“lost.jpg”];
self.rangeStatusImageView.hidden=否;
self.signalStatusImageView.hidden=是;
self.descriptionStateLabel.text=@“接收信号…持续存在问题,请联系我”;
[UIView animateWithDuration:1.0
延迟:0.0
选项:UIViewAnimationOptionCurveEaseIn
动画:^{
self.rangeStatusImageView.alpha=0.3;
}
完成:^(布尔完成){
[UIView animateWithDuration:1.0
延迟:0.0
选项:UIViewAnimationOptionCurveEaseOut
动画:^{
self.rangeStatusImageView.alpha=1.0;
}
完成:无];
}];
打破
}
案例CLProximity立即:
{
如果([currentBeaconMinor floatValue]==128)
{
NSLog(@“128”);
[self-PerformsgueWithIdentifier:@“presentSegue1”发送方:self];
}
else if([currentBeaconMinor floatValue]==228)
{
NSLog(@“228 228”);
[self-PerformsgueWithIdentifier:@“presentSegue2”发送方:self];
}
else if([currentBeaconMinor floatValue]==328)
{
NSLog(@“328 328 328”);
[self-PerformsgueWithIdentifier:@“presentSegue3”发送方:self];
}
打破
}
病例CLProximityNear:
{
self.rangeStatusImageView.image=[UIImage ImageName:@“near.jpg”];
self.signalStatusImageView.hidden=否;
AudioServicesPlayAlertSound(KSystemsSoundId_振动);
[UIView animateWithDuration:1.0
延迟:0.0
选项:UIViewAnimationOptionCurveEaseIn
<key>NSLocationAlwaysUsageDescription</key>
<string>This application monitors your location to show you promotional offers in shops you're passing by.</string>