objective c - Beacon didRangeBeacons in Region not Called -
my code working months ago. dint chnage anything
i dont understand why didrangebeacons in region not trigger when launch app :
#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 manager instance. self.beaconmanager = [[estbeaconmanager alloc] init]; // setup delegate self.beaconmanager.delegate = self; // avoiding unknown state or not self.beaconmanager.avoidunknownstatebeacons = no; // create sample region object (beacons in case have same uuid , 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 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 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 sort array of beacons distance nssortdescriptor *sortdescriptor; sortdescriptor = [[nssortdescriptor alloc] initwithkey:@"distance" ascending:yes]; nsarray *sortdescriptors = [nsarray arraywithobject:sortdescriptor]; // sorting array of beacons // beacon array sorted based on distance // closest beacon first 1 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 array of beacons self.beaconsarray = [beacons sortedarrayusingdescriptors:sortdescriptors]; //updating selected beacon first element of array (closest beacon) if(self.selectedbeacon != [beacons objectatindex:0] ) { self.selectedbeacon = [beacons objectatindex:0]; currentbeaconminor = self.selectedbeacon.minor; } } // switch on proximity of 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]; } }
i have break point @ line after pragma mark , never reach code. dont understand why.
thanks help.
i found solution :
i updated info.plist file :
<key>nslocationalwaysusagedescription</key> <string>this application monitors location show promotional offers in shops you're passing by.</string>
in iphone have change settings localisation app "always"
Comments
Post a Comment