vipul mittal
vipul mittal

Reputation: 17401

invoking application when not running and iBeacon in range

I am working on an iPhone app that notifies a user when he enters in the region of an iBeacon.

I have a few question regarding the same:

From documents:

Monitoring launches app when entered in the region of iBeacon being monitored.

But the behavior is:

It only works when phone is awakened i.e. When display is turned on. But when app is not running and display is off nothing happens same is the case when display is on and user enters in the region of the beacon.

Is it possible to launch application when users enter/exits the region even when display is off or on not just when phone is awakened?

I checked this iBeacon Notification when the app is not running link, which shows it is possible. I am monitoring an iBeacon but not able to get the expected behavior. Am I missing something??

Any help is appreciated.

Upvotes: 2

Views: 2125

Answers (2)

csexton
csexton

Reputation: 24783

Yes, you can get notified on entering a region in the background. This will happen as long as:

  • The app has been opened at least once
  • The user did not kill the app directly (by quitting the process, not just dismissing it)

Now understanding how it behaves a a little more nuanced.

At my company we've done a fair amount of research on this. In fact a colleague of mine wrote a great blog post about the behavior: iBeacon Monitoring in the Background and Foreground.

What was unexpected was how long it can take to get a didEnterRegion in the background:

Condition                                      Max time to detect a region change
--------------------------------------------   ----------------------------------
Phone awakened,notifyEntryStateOnDisplay=YES   1 second
Phone awakened, notifyEntryStateOnDisplay=NO   NEVER
UIBackgroundModes=location ON                  up to 15 minutes
UIBackgroundModes=location OFF                 up to 15 minutes

Upvotes: 4

James Frost
James Frost

Reputation: 6990

There are a couple of properties you can set on a CLBeaconRegion to alter when your app will be notified about a change to the user's location in relation to that region:

  • notifyOnEntry - you will be notified via locationManager:didEnterRegion: when the user enters the region
  • notifyOnExit - you will be notified via locationManager:didExitRegion: when the user exits the region
  • notifyEntryStateOnDisplay - you will be notified via locationManager:didDetermineState:forRegion: when the user wakes their device's screen up and they are inside the region

Note that you must completely exit a region before didEnterRegion: is called again, and sometimes it can take a minute or more for the device to properly register that you have left a region. Because a beacon can broadcast up to 30 or 50 meters (or perhaps more), you either have to move a long way away from a beacon to leave a region or otherwise turn the beacons off , wait for a minute or so, and then back on to trigger a change.

Upvotes: 0

Related Questions