2014-12-16 3 views
1

Мой код работал отлично несколько месяцев назад. я впадина chnage ничегоBeacon didRangeBeacons in Region not Called

Я не понимаю, почему didRangeBeacons в регионе не срабатывает, когда я запустить мое приложение:

#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]; 
    } 
} 

У меня есть точка разрыва на линии после знака прагма, он никогда не достигнет этого кода. Я действительно не понимаю, почему.

Благодарим за помощь.

+0

Есть вы назначили делегата менеджера местоположений этому классу? – Greg

+0

Do u Mean self.beaconManager.delegate = self; ? –

+0

Мой код работал отлично, у меня такой же код для многих приложений. Я не понимаю, почему все мои приложения не работают сейчас. что-то новое или недавно изменилось? –

ответ

2

Я нашел решение:

я обновил файл Info.plist с:

<key>NSLocationAlwaysUsageDescription</key> 
<string>This application monitors your location to show you promotional offers in shops you're passing by.</string> 

В Iphone у меня есть изменить параметры локализации для моего приложения к «всегда»

+0

Дополнительная информация о: https://community.estimote.com/hc/en-us/articles/203393036-Estimote-SDK-and-iOS-8-Location-Services –