iBeacons issue: Did enter region triggers multiple times - ios

I'm working with a sample app for iBeacon region monitoring functionality. The Issue(not sure if it is) that I was unable to resolve is "didEnterRegion:" fires continuously for more than 2 times when I enter the region. This happens to send the local notification more than once or the times that this method fires when the app is in minimized mode.
Can anybody tell me how to resolve this.
Thanks,

It is common for a glitch in iOS to cause a didExitRegion event followed within a second by a didEnterRegion event. You can filter these out in your code by storing in an NSDate variable the time you last exited the region. When you get a didEnterRegion callback, you simply ignore it if the exit timestamp was within the last few secs.
If you are really getting these continuously as you say, something else is wrong that you may need to fix. It is possible that your iBeacon is not transmitting at least once every three seconds. This would cause constant exit/entry callbacks.

Related

sometimes didExitRegion event missed of iBeacon

Sometimes app didn't execute the didExitRegion event in the following cases.
Bluetooth OFF
Keep device/beacon away
Switched OFF the Beacon
After the missed didExit event, didEnter even also won't execute because the iOS(OS/App) thinks beacon still exists. It happens until restart the power cycle of the beacon.
I have tried to overcome this issue programmatically. But it seems like I didn't fix it.
I have tried the following steps to overcome this issue
Based on the ranging/didDetermine status I have executed didExit event manually. (It didn't help)
I've tried with restart the beacon monitoring (It didn't help)
Aspected Result: didEnter/didExit events must be worked when the beacon is coming to the range or exiting from the range.

Get CMMotionActivityManager updated when app is terminated

Right now I'm developing an app that needs to know what the user is doing activity-wise (standing still, running, walking, ect.) all the time. I found that using CMMotionActivity might be a good way to do this.
Except for one thing: when the app is terminated, the CMMotionActivityManager stops running. First I tried to solve this by creating a cronjob to send remote silent notifications every n minutes and wake the app for motion data. I then did some research and found that silent notifications do not wake the app.
After some more research, I found that using Location and startMonitoringSignificantLocationChanges the app will be woken from a terminated state when the user moves 500 meters or more.
However, I believe I need more data then one point every 500 meters. Something more along the lines of one point every 5 minutes would be nice. But the sense I get is that startMonitoringSignificantLocationChanges won't update even if the user stands still for a whole day.
So my question in a nutshell is two parts:
Am I misunderstanding startMonitoringSignificantLocationChanges? Will it give me a notification every so often even if the user doesn't move?
If I don't misunderstand significant changes, is there any way to get Motion Updates every n minutes even when the app is terminated?
Thanks friends.

Background fetch regularly

I want to upload the location in background every 30secs to 1min. Is it possible?
I have found that I can set UIApplicationBackgroundFetchIntervalMinimum. But I looked around this constant to tell the device to fetch about every 30mins. Any way to do that? Thanks.
I don't know the exact purpose of yours for uploading location for every 30 secs. It's not recommended to do so. I think you can go for MonitoringSignificationChanges in CoreLocation framework. It will give you update whenever there is a significant change in location. It helps in saving the battery.
Starts the generation of updates based on significant location changes by the following method:
func startMonitoringSignificantLocationChanges()
This method initiates the delivery of location events asynchronously, returning shortly after you call it. Location events are delivered to your delegate’s locationManager(_:didUpdateLocations:) method. The first event to be delivered is usually the most recently cached location event (if any) but may be a newer event in some circumstances. Obtaining a current location fix may take several additional seconds, so be sure to check the time stamps on the location events in your delegate method.
Fore more info: Apple Docs
Your approach has multiple problems. Most apps are not allowed to run continuously in the background like you want to do. You get ~3 minutes of background time, and then your app gets suspended. Navigation apps are an exception. If your app is a navigation app you are allowed to run continuously in the background.
Polling the GPS every 30 seconds is also a bad idea unless you're a navigation app. You'll quickly drain the user's battery.
Likewise uploading the user's location every 30 seconds will keep the cellular/WiFi radio on the phone powered up nearly constantly, which will drain the user's battery quite rapidly.

Single local notification in didEnterRegion

Using the estimote beacons, I get multiple local notifications fired from didEnterRegion. I only range & monitor 1 region under which all my beacons reside.
I am trying to restrict this functionality so that users only get notified once whilst in the region. I would think this is out-of-the-box functionality since there's a corresponding didExitRegion event, so in essence you only get 1 notification whilst inside the region.
I don't see this behaviour though. Event didEnterRegion fires multiple times while I am physically inside the region. So I implemented a counter that's initially set to 0 and increments by 1 every time I'm inside didEnterRegion. I only allow the local notification to fire when the counter < 1.
But this has left me wondering; how will this work when the app is not running? Also, by doing it this way (i.e. not resetting the counter back to 0 via didExitRegion) do I only notify the user just once throughout the presence of the app on his phone, regardless the times he will physically enter / exit the region (while the app is installed and not running)? I want to inform him just once whilst in the region, and not just once in general.
I'm clearly confused with this, so would love to hear any feedback.
Make sure that you're not monitoring the same beacon multiple times, by inspecting the monitoredRegions property of your ESTBeaconManager/CLLocationManager.

Getting false positive alert with beacon exit / enter requin

I have this iBeacon application in swift that perform some task when didExitRegion and didEnterRegion are called. Everything works well except I am getting false alert in a way that I am within the beacon range and all the sudden didExitRegion is getting fired and immediately in a few secs later didEnterRegion getting fired again. This happens when either the phone or the beacon hasn't moved or anything blocked the signals.
I read somewhere that this is a bug on the Apple side. Not sure how true this is, but what's the work around this?
I was thinking to get the Alt, Lat every time the didExit is getting fired and compared with with the previous values or if there is a better way of doing this?
Thanks
I think a potential solution could be to move the code currently inside of your didExitRegion method into a new new method. In didExitRegion start a timer for 5 seconds (or whatever you find to work best) inside to call the new method when it fires.
Then, if didEnterRegion is called while the timer is running, cancel the timer and return from didEnterRegion.
From my experience, it seems this is something that happens when your device loses the beacon's signal momentarily while still within range. My apps have sent me didEnterRegion notifications every 5 minutes when I've been sitting right next to the beacon. From what I've read, the performance of the app depends on the quality of the beacon as far as signal strength and signal frequency.
This is a problem with beacons that do not transmit frequently enough. A didExitRegion event will fire on iOS if no beacon packets have been detected in 30 seconds. If a beacon is nearby and transmitting at the recommended 10 Hz, false positives are very, very rare.
Many beacon manufacturers reduce transmission rates to save battery, some making transmissions happen as seldom as every 5 seconds. This leads to bad performance and false exits. Not all beacon packets transmitted get received due to radio noise and interference. In practice, only 80-90% do. With a beacon transmitting every 5 seconds, 6 missed packets in a row will cause an exit event. This usually will not happen, but sometimes it will.
The best solution is to configure the beacon to transmit more often, ideally at 10 Hz or more. If you get a beacon that lets you do this and make it transmit that often, false exits will be very, very rare.

Resources