How does iBeacon wake up our app? For how long? And how to extend that time?

后端 未结 1 1988
太阳男子
太阳男子 2021-02-03 14:31

after some research of iBeacon I came up with the following questions that I couldn\'t find extended help:

  1. How does iBeacon wake up our app? Does it wake up our

相关标签:
1条回答
  • 2021-02-03 14:48

    Some answers:

    1. An iBeacon can wake up your app into the background using monitoring APIs. It can do this even if your app has not been launched since device reboot, or even if the app has been killed from the task switcher (although the latter requires iOS 7.1+) This works by your app calling the startRangingBeaconsInRegion: method on CLLocationManager, and also implementing the CLLocationManagerDelegate protocol's locationManager:didDetermineState:forRegion:, locationManager:didEnterRegion: and/or locationManager:didExitRegion: methods.

    2. Even if your app is not running, your app will get launched into the background and the above methods called when a beacon matching the passed region definition is detected. You can execute any code you want in this time that doesn't require a user interface. Typically, this includes updating application state, calling a web service, or sending a local notification to encourage the user to bring the app to the foreground. (And no, you cannot programmatically bring your app to the foreground.)

    3. The app only gets to run for about five to ten seconds in the background before being suspended again. (If your app were already in the foreground, it would get to continue running indefinitely.) If it is suspended after this brief time your class implementing the UIApplicationDelegate protocol applicationWillResignActive: method gets called.

    4. You can request additional background time by calling the beginBackgroundTaskWithExpirationHandler: method of the UIApplication class. But getting this extra time is not guaranteed, and you cannot continue to do this indefinitely.

    5. Once your app enters a region and you get a background notification, you cannot get a second notification to wake up your app for the same region until you exit it. You can game this a bit by defining multiple regions and having multiple beacons that might trigger more entries and exits. But these are all workarounds. In general you cannot relaunch the app with this technique if there is no additional entry/exit event.

    0 讨论(0)
提交回复
热议问题