2 Replies
      Latest reply on Oct 4, 2016 10:17 AM by dsm
      FocusonFei Level 1 Level 1 (0 points)

        I am developing a program that use the ibeacon technology,and we hope the program scan the ibeacon in the background mode continuously.

        After look in a lot of information,it is allowable that to be detected and then runnning in the background about 10s.Then it also be suspended or killed by the system.

        Can I relize this function by now???


        If you have any information about this ,pls tell me or send mail to 331035175@qq.com. Thx very much.

        Dont care about my poor English.hhh...

        • Re: Scanning the iBeacon in the background mode continuously
          eskimo Apple Staff Apple Staff (13,925 points)

          You typically do this via Core Location, that is, by creating a CLBeaconRegion that describes your beacon and then setting up significant location change to track that.  Is that not working for you?

          Share and Enjoy

          Quinn “The Eskimo!”
          Apple Developer Relations, Developer Technical Support, Core OS/Hardware
          let myEmail = "eskimo" + "1" + "@apple.com"

            • Re: Scanning the iBeacon in the background mode continuously
              dsm Level 1 Level 1 (0 points)

              Hey eskimo. I'm using a single CLBeaconRegion with CLLocationManager's startMonitoringForRegion: successfully on iOS 8 and 9, but on iOS 10.0.x my app is no longer being awoken when a beacon is turned on nearby. This problem is happening on all three of my iOS 10.0.x devices, but working successfully on five of my other devices running iOS 8.4.1 through 9.3.5.


              Is this a known issue with iOS 10?


              For the record, I have NSLocationAlwaysUsageDescription defined in the Info.plist, that CLLocationManager.authorizationStatus is kCLAuthorizationStatusAuthorizedAlways, and I have verified that locationManager:didStartMonitoringForRegion: is received after calling the code below:


                CLBeaconRegion* region = [self regionToMonitor]; // Generates the beacon region I'm interested in
                if (region && ![self.locationManager.monitoredRegions member:region]) {
                   region.notifyEntryStateOnDisplay = YES;
                   [self.locationManager startMonitoringForRegion:region];


              I can have all 8 devices running the same code in the background while sitting on a table, and when the beacon is turned on the five iOS 9 and lower devices instantly wake up with locationManager:didDetermineState:forRegion:, yet the three iOS 10 devices remain silent indefinitely.


              Follow up: I've tried running in the foreground too, and it seems I cannot identify iBeacons on iOS 10 at all.


              Is there anything missing, perhaps, that I need specifically for iOS 10?






              Follow up 2: In case it helps others, I found out that the CLBeaconRegion.identifier (not UUID) is important when it comes to cleaning up previous monitoring, which can prevent new monitoring from working, despite locationManager:didStartMonitoringForRegion: making you think everything is fine.


              So here's my new code that starts listening (which seems to be ok on all versions of iOS I've tested):


              - (void)startListening {
                // Clean up any possible monitoring based on the kBeaconIdentifier constant
                CLBeaconRegion* stopRegion = [[CLBeaconRegion alloc] initWithProximityUUID:[NSUUID UUID] identifier:kBeaconIdentifier];
                [self.locationManager stopMonitoringForRegion:stopRegion];
                // Now start monitoring with the UUID we care about...
                CLBeaconRegion* region = [[CLBeaconRegion alloc] initWithProximityUUID:self.uuid identifier:kBeaconIdentifier];
                region.notifyEntryStateOnDisplay = YES;
                [self.locationManager startMonitoringForRegion:region];

              And if you've been developing and trying out different beacon identifiers with the same UUID, you could have problems. So check out the monitored regions and clean up if necessary.

              The following text in the SDK (which is confusingly written, btw) seems to explain that this is necessary:

              *  startMonitoringForRegion:
              *  Discussion:
              *      Start monitoring the specified region.
              *      If a region of the same type with the same identifier is already being monitored for this application,
              *      it will be removed from monitoring. For circular regions, the region monitoring service will prioritize
              *      regions by their size, favoring smaller regions over larger regions.
              *      This is done asynchronously and may not be immediately reflected in monitoredRegions.