Ranging Beacons only works when app running?

后端 未结 5 700
说谎
说谎 2021-01-29 23:05

I am having difficulties getting this to work for when the app is not running. I have locationManager:didRangeBeacons:inRegion: implemented and it is called when th

5条回答
  •  生来不讨喜
    2021-01-29 23:37

    Monitoring can launch an app that isn't running. Ranging cannot.

    The key to having monitoring launch your app is to set this poorly documented flag on your CLBeaconRegion: region.notifyEntryStateOnDisplay = YES; This can launch your app on a region transition even after completely rebooting your phone. But there are a couple of caveats:

    1. Your app launches into the background only for a few seconds. (Try adding NSLog statements to applicationDidEnterBackground and other methods in your AppDelegate to see what is going on.)
    2. iOS can take its own sweet time to decide you entered a CLBeaconRegion. I have seen it take up to four minutes.

    As far as ranging goes, even though you can't have ranging wake up your app, you can make your app do both monitoring and ranging simultaneously. If monitoring wakes up your app and puts it into the background for a few seconds, ranging callbacks start up immediately. This gives you a chance to do any quick ranging actions while your app is still running.

    EDIT: Further investigation proves that notifyEntryStateOnDisplay has no effect on background monitoring, so the above should work regardless of whether you have this flag. See this detailed explanation and discussion of delays you may experience

提交回复
热议问题