2014-12-16 2 views
1

내 코드가 몇 달 전 완벽하게 작동했습니다. 내가 힘 chnage 아무것도 내가 내 응용 프로그램 실행하면 지역의 didRangeBeacons가 실행되지 이유를 이해 해달라고호출되지 않은 지역의 비콘 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

가 가지고 내 앱 현지화에 대한 설정을 변경해야 아이폰에서

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

: 내가 가진의 Info.plist 파일을 업데이트

: – Greg

+0

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

+0

내 코드가 완벽하게 작동했습니다. 많은 앱에서 동일한 코드가 있습니다. 왜 내 모든 애플 리케이션이 지금은 작동하지 이해가 안나. 새로운 것이나 최근에 바뀐 것이 있습니까? –

답변

2

나는 해결책을 발견 이 클래스에 위치 관리자 위임자를 설정 했습니까?
+0

에 대한 자세한 정보 : https://community.estimote.com/hc/en-us/articles/203393036-Estimote-SDK-and-iOS-8-Location-Services –