title: iBeacon: Settings of CLBeaconRegion identifier?
body: <p>I use Apple <a href="https://developer.apple.com/library/ios/samplecode/AirLocate/Introduction/Intro.html" rel="nofollow">AirLocate</a> demo App to create an iBeacon.</p>
  
  <ul>
  <li>Identifier: com.example.apple-samplecode.AirLocate</li>
  <li>UUID: E2C56DB5-DFFB-48D2-B060-D0F5A71096E0</li>
  <li>Major: 0</li>
  <li>Minor: 0</li>
  <li>Measured Power: -59</li>
  </ul>
  
  <p>The signal is <strong>successfully</strong> picked up by an Android beacon detector App.</p>
  
  <p>However, when I use the following codes to detect the iBeacon in iOS 8, the beacon does not show up:</p>
  
  <pre><code>self.coreLocation = [[CLLocationManager alloc] init];
  _coreLocation.delegate = self;
  NSString *identifier = [NSString stringWithFormat:@"com.example.apple-samplecode.AirLocate.%@", @"E2C56DB5-DFFB-48D2-B060-D0F5A71096E0"];
  CLBeaconRegion *region = [[CLBeaconRegion alloc] initWithProximityUUID:uuid identifier:identifier];
  if(region) {
      region.notifyOnEntry = YES;
      region.notifyOnExit = YES;
      [_coreLocation startMonitoringForRegion:region];
  }
  </code></pre>
  
  <p>No matter which value I use in the identifier field, the beacon is never found by <code>CLLocationManager</code>. Its delegates, <code>didDetermineState:</code> and <code>didRangeBeacons:</code> were never been called. However, delegate <code>monitoringDidFailForRegion</code> received this:</p>
  
  <blockquote>
    <p>The operation couldn’t be completed. (kCLErrorDomain error 4.)</p>
  </blockquote>
  
  <p>After looked up some documentations online, the error code 4 means:</p>
  
  <blockquote>
    <p>Access to the region monitoring service was denied by the user.</p>
  </blockquote>
  
  <p>But I use the following codes to prove my app is authorized to monitor region:</p>
  
  <pre><code>- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
      if(status == kCLAuthorizationStatusDenied) {
          NSLog(@"didChangeAuthorizationStatus: Denied");
      } else if(status == kCLAuthorizationStatusNotDetermined) {
          NSLog(@"didChangeAuthorizationStatus: Not Determined");
      } else if(status == kCLAuthorizationStatusAuthorizedAlways) {
          NSLog(@"didChangeAuthorizationStatus: Authorized Always");
      } else if(status == kCLAuthorizationStatusAuthorizedWhenInUse) {
          NSLog(@"didChangeAuthorizationStatus: Authorized When In Use");
      } else if(status == kCLAuthorizationStatusRestricted) {
          NSLog(@"didChangeAuthorizationStatus: Restricted");
      } else {
          NSLog(@"didChangeAuthorizationStatus: Unknown");
      }
  }
  </code></pre>
  
  <p>and it returns: </p>
  
  <blockquote>
    <p>didChangeAuthorizationStatus: Authorized When In Use</p>
  </blockquote>
  
  <p>Given that:</p>
  
  <ul>
  <li>I'm using iPhone 5s with iOS 8.1.2</li>
  <li>I added <code>NSLocationWhenInUseUsageDescription</code> in <code>Info.plist</code></li>
  <li>In Capabilities page, I enabled "Location updates" and "Uses Bluetooth LE accessories" (Xcode added corresponding entries to <code>Info.plist</code>)</li>
  <li>Requested "When In Use" Authorization via <code>[self.coreLocation requestWhenInUseAuthorization]</code></li>
  <li>Allowed "Location Service" and "Push Notification" during first launch of the App</li>
  <li>Airplane Mode is OFF</li>
  <li>Bluetooth is ON</li>
  <li>Wi-Fi is ON, connected to Internet</li>
  <li>Settings > General > Background App Refresh is ON</li>
  <li>Settings > Privacy > Locations Services > My App > While Using (tick)</li>
  <li><code>[CLLocationManager isMonitoringAvailableForClass:[CLRegion class]]</code> returns YES</li>
  </ul>
  
  <p>What did I miss to cause this error 4 ? Also, does the identifier necessary to match with the iBeacon's Bundle Identifier (why Android can detect all beacons, but iOS need to specify identifiers)?</p>
  
  <p>Reference: <a href="https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/LocationAwarenessPG/RegionMonitoring/RegionMonitoring.html" rel="nofollow">Region Monitoring and iBeacon</a></p>