Hello , my code was working perfectly , i used it on many apps.
Today my apps dont works.
The delegate didRangeBeacons in Region never called.
Here is my code please help me . i have to show that app today.
-------->
#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:ESTIMOTEPROXIMITYUUID 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];
}
- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. }
#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 Pharmacie Lloyd's Pharma Soleilmont.";
break;
}
default:
break;
}
self.beaconsArray = [beacons sortedArrayUsingDescriptors:sortDescriptors];
}
}