invoking application when not running and iBeacon in range - ios

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.

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

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.

Related

Terminated App not wakeup with iBeacon packet

Can iOS receive iBeacon packet in sleep state and wake up the app?
I killed an app and restarted, then kept the phone in sleep mode. The device was was in beacon region when device reboot and I kept the device screen off after reboot.
My iOS app is not waking, so I suspect its not receiving iBeacon packet.
I checked the system log and found that the didEnterRegion procedure is not getting called.
Does app wakeup works incase of force terminated app and does iOS receive iBeacon packet in reboot and immediate sleep state?
If I make screen on then it starts working immediately but if screen is off after reboot its not receiving iBeacon packet.
Yes, iOS CoreLocation will launch your app on region entry or region exit, and works even after force termination after iOS 7.1.1. You will only get the appropriate callback if you set up your CLLocationManagerDelegate in the AppDelegate's didFinishLaunchingWithOptions method. If you do not set this up in that method, then CoreLocation will not know to make the callback after app launch.
Testing entry events across an app restart can be a little tricky, so here are a few tips to avoid pitfalls:
If is critical that your app think that it is "outside" the region when it was last running. If it was "inside" the region when it was last running, it won't necessarily get another entry callback because it will think it never left. When testing, make absolutely sure you get a didExit callback or a didDetermineState callback that says it is out of region before you kill the app or reboot. Verify this with a NSLog statement, a local notification, or some custom UI indicator added to a screen of your app.
If you reboot an iOS device, CoreLocation is not fully initialized right away -- I have seen it take 5 minutes after the screen comes on before I get any callbacks. Be sure you wait long enough.
Once CoreLocation is fully initialized, region entry events typically happen within one second of when the beacon comes into range. However, if the limited bluetooth hardware assist pattern slots are all full on the device (typically this happens if you have a few other beacon apps that have used them all), then entry events fall back to software scans that happen only every 10 minutes or more. An entry event can take that long in such a situation. Make sure you wait long enough before assuming it isn't working.

Sometimes App is not giving notification of iBeacon when app is kill by user in ios

I am using iBeacon Technology in my application.When I open the app,beacon monitoring gets started and after that I kill the application and put the phone in sleep mode or lock the screen. If I go near to the beacon then sometimes app starts monitoring and sometimes not. Don't know what's the issue? I have set three flag for monitoring beacon region as below.
beaconRegion.notifyOnEntry = true;
beaconRegion.notifyOnExit = true;
beaconRegion.notifyEntryStateOnDisplay= true;
And When I press the lock button of the iphone. It starts monitoring for beacons and if I am in beacon region then it works perfectly..
Can anyone help me out ?
I have been working with iBeacon for around a year now, i have had the same scenarios encountered.
As per my experience with this if you are already inside a region, it takes some time to notify the 'didEnterRegion' delegate method. But if you are outside region a then entering the same you are likely to get the delegate called instantly and this depends on the Beacon Manufacture you are testing with. [More accuracy were found with RadBeacon, Estimote and Kontakt ]
Normally the TxPower configured to the beacons will be +4 dBm thats a Beacon can transmit till 70m/230". Try with going out of the region with the App in killed state and then enter the region.
When we set notifyOnEntry, notifyOnExit to YES/true, the control is with the OS LocationManager wether to notify the App about the region entry state, and you can handle it with a Notification thrown to the User and start Monitoring and then Ranging for the encountered region.

How long does it take to detect an iBeacon while region monitoring?

Take this scenario: user has an iPhone in the pocket passing by an iBeacon. Her phone is region monitoring for it. How much time is needed in real world to from entering the region to the moment app is woken up?
I have found an excellent article on the subject by David G. Young (http://developer.radiusnetworks.com/2013/11/13/ibeacon-monitoring-in-the-background-and-foreground.html) but I can't believe it can really take up to 15 minutes.
That would mean that all iBeacon home automation scenarios are simply unusable because you won't neither wait 15 mitutes in dark room for lights to switch on neither you would switch on the lights by actively using an app. Door opening and locking is another situation where iBeacon would be unusable (and NFC would work much better here). Or am I missing something?
I have an app that ranges for an iBeacons. It first grabs a list of couple proximityUUIDs and registers them as monitored regions.
When the device enters that region, it takes just 1 to several seconds (iPhone 5S) to post me a local notification on didEnterRegion: event.
When the app is in front, it starts ranging the beacon immediately in current region (if any) and updates happen in about one-second intervals.
When the app is in background, ranging is not enabled, otherwise it would immediately report that the beacon is gone (if you leave its range).
HOWEVER, It can really take up to 15 minutes (I've experienced this) for the device to post the didExitRegion: when in background in the worst case, when there is just significant location monitoring enabled combined with bad or no network. Otherwise it happens until about a minute.
Sorry, this didn't fit into a comment.

Set range region iBeacons

I'm having some major problems with iBeacons.
I can't figure out at all how I control the distance that triggers some sort of event (like the notification). I'm only allowed to send notification when i enter or exit region but i'd like to send notification when i'm near or immediate/
Where am I missing these things in the documentation ?
Thx !
The short answer is that you can't. Beacons enter the region as soon as the beacon is detected.
What you can do is to turn on both enter/exit notifications AND beacon ranging. Then in your app's handler for locationManager:didRangeBeacons:inRegion: you can either use the proximity property (far/near/immedate) or use the "Accuracy" reading (which is really a badly named approximate distance reading.)
You would ignore the ranging notices until you decide the user is close enough.
However, there's a big problem with this. If your app is in the background, you get a didEnterRegion notice, followed by about 5 seconds of ranging message. Then the ranging messages stop and your app goes back to sleep. After those 5 seconds you won't get any more notifications about that region until the user exits it.

Will iOS region monitoring call didEnterRegion on my app if my app is in a terminated state?

Will iOS region monitoring launch my app in the background if the user enters a region that was successfully being monitored for prior to the app being terminated?
I know that the significant change API will do so and will let me know at launch time via the inclusion of the UIApplicationLaunchOptionsLocationKey key. If region monitoring will wake my app up out of a terminated state too, then what does the launch process look like? Is there a special key I should be looking for?
Yes, see Region Monitoring
In iOS, regions associated with your app are tracked at all times,
including when your app is not running. If a region boundary is
crossed while an app is not running, that app is relaunched into the
background to handle the event. Similarly, if the app is suspended
when the event occurs, it is woken up and given a short amount of time
(around 10 seconds) to handle the event.
I have been searching for similar answer, but came across this: Region monitoring in ios 7
Seems like if the app is manually terminated by the user in iOS 7, location notifications will not wake the app to process it. Apple employee has commented here https://devforums.apple.com/thread/209302?tstart=0

Resources