2017-01-09 8 views
0

iOS 장치를 iBeacon으로 변환 한 다음 코어 위치 'API를 사용하여 신호를 감지합니다. 근접성. 이제는 작동하지만, 때로는 정의 된 거리 (10m 떨어진 거리)에서 때때로 비컨 신호가 보이지 않는 신호를 보거나 비컨 근처의 신호를 보게되는 예기치 않은 동작을 봅니다.proximity API로 일관성없는 동작 - iOS iBeacon

이 동작을보다 일관성있게 유지할 수있는 방법이 있습니까? 여기

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    self.beaconSwitch.on = NO; 
    self.beaconView.backgroundColor = [UIColor clearColor]; 
    self.peripheralManager = [[CBPeripheralManager alloc] initWithDelegate:self queue:nil]; 
    BeaconRegion *beaconRegion = [[BeaconRegion alloc] init]; 
    self.beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:beaconRegion.uuid major:[beaconRegion.major shortValue] minor:[beaconRegion.minor shortValue] identifier:beaconIdentifier]; 
} 


- (void)viewWillDisappear:(BOOL)animated { 
    [super viewWillDisappear:animated]; 
    [self.peripheralManager stopAdvertising]; 
} 


- (IBAction)doneButtonPressed:(id)sender { 
    [self dismissViewControllerAnimated:YES completion:nil]; 
} 

- (IBAction)beaconSwitchPressed:(id)sender { 
    if (self.beaconSwitch.on == true) { 
     self.beaconView.beaconState = BNBeaconStateBroadcasting; 

     NSDictionary *data = [self.beaconRegion peripheralDataWithMeasuredPower:nil]; 
     [self.peripheralManager startAdvertising:data]; 
    } else { 
     self.beaconView.beaconState = BNBeaconStateStop; 
     [self.peripheralManager stopAdvertising]; 
    } 
} 

내가 비콘에 내 아이폰 OS 장치를 변환하고 방법입니다

을 그리고 여기에 내가 그것의 근접 무엇입니까 방법입니다 : 지금

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    BeaconRegion *beaconRegion = [[BeaconRegion alloc] init]; 
    self.beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:beaconRegion.uuid identifier:beaconIdentifier]; 
    self.beaconRegion.notifyOnEntry = YES; 
    self.beaconRegion.notifyOnExit = YES; 
    self.beaconRegion.notifyEntryStateOnDisplay = YES; 
    self.locationManager = [[CLLocationManager alloc] init]; 
    self.locationManager.delegate = self; 
    self.detectionSwitch.on = NO; 
} 

- (IBAction)beaconDetectionSwitchPressed:(id)sender { 
    if (self.detectionSwitch.isOn) { 
     [self.locationManager startMonitoringForRegion:self.beaconRegion]; 
     [self.locationManager requestStateForRegion:self.beaconRegion]; 
    } else { 
     self.lastProximity = CLProximityUnknown; 
     [self.locationManager stopMonitoringForRegion:self.beaconRegion]; 
     [self.locationManager stopRangingBeaconsInRegion:self.beaconRegion]; 
     self.titleLabel.text = @""; 
     self.messageLabel.text = @""; 
    } 
} 

- (void)viewWillDisappear:(BOOL)animated { 
    [super viewWillDisappear:animated]; 
    [self.locationManager stopMonitoringForRegion:self.beaconRegion]; 
    [self.locationManager stopRangingBeaconsInRegion:self.beaconRegion]; 
    self.locationManager = nil; 
} 

- (void)locationManager:(CLLocationManager *)iManager didEnterRegion:(CLRegion *)iRegion { 
    NSLog(@"Detected a beacon"); 

    if (![self.beaconRegion isEqual:iRegion]) { 
     return; 
    } 

    NSLog(@"Entered into the beacon region = %@", iRegion); 

    [self.locationManager startRangingBeaconsInRegion:self.beaconRegion]; 
} 

- (void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region { 
    NSLog(@"Ranging beacon successful"); 

    if (beacons.count > 0) { 
     CLBeacon *nearestBeacon = beacons[0]; 
     CLProximity currentProximity = nearestBeacon.proximity; 

     if (currentProximity == self.lastProximity) { 
      NSLog(@"No Change in Beacon distance"); 
     } else { 
      self.lastProximity = currentProximity; 
      [self updateUserAboutProximity]; 
     } 
    } else { 
     self.lastProximity = CLProximityUnknown; 
    } 
} 


- (void)updateUserAboutProximity { 
    NSString *title = @"--"; 
    NSString *message = @"--"; 
    switch (self.lastProximity) { 
     case CLProximityUnknown:{ 
      title = @"No Beacon"; 
      message = @"There is no nearby beacon"; 
     } 
      break; 

     case CLProximityImmediate:{ 
      title = @"Immediate Beacon"; 
      message = @"You are standing immediate to video wall!"; 
     } 
      break; 

     case CLProximityNear:{ 
      if (self.isServerCallOn) { 
       title = @"Near Beacon"; 
       message = @"You are standing near to video wall!"; 
      } else { 
       title = @"Near Beacon"; 
       message = @"You are standing near to video wall! Initiating a server call."; 

       if (!self.ignoreSeverCallTrigger) { 
        self.isServerCallOn = YES; 
        [self talkToServer]; 
       } else { 
        NSLog(@"Ignoring server call trigger"); 
        message = @"Ignoring server call trigger!"; 
       } 
      } 
     } 
      break; 

     case CLProximityFar:{ 
      title = @"Far Beacon"; 
      message = @"You are standing far from video wall!"; 
     } 
      break; 
     default: 
      break; 
    } 
    self.titleLabel.text = title; 
    self.messageLabel.text = message; 
} 

- (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region { 
    if (state == CLRegionStateInside) { 
     NSLog(@"Starting Ranging"); 
     [self.locationManager startRangingBeaconsInRegion:self.beaconRegion]; 
    } 
} 

- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status { 
    if (![CLLocationManager locationServicesEnabled]) { 
     NSLog(@"Location Service Not Enabled"); 
    } 

    if ([CLLocationManager authorizationStatus] != kCLAuthorizationStatusAuthorizedAlways) { 
     NSLog(@"Location Service Not Authorized"); 
    } 
} 

답변

0

을, 나는에 조건을 뒀다 수신 된 신호 강도 표시기 (rssi) 값을 계산하고 Near proximity에서 -60보다 큰 값을 수락하면 거리를 좀 더 예측 가능하게 만듭니다. 따라서, Nearby proximity 내에서 rssi> -60 인 경우 내 행동을 트리거합니다.