Core Location, iBeacon & Region Monitoring - ios

I am looking to make an App similar to that of the iOS reminders app. Where a user can essentially set reminders to go off when a user has entered or left a certain area.
I am new to iOS app development and have been doing some research into what might be needed but I am getting a bit confused and was wondering if someone could clarify a few things for me.
From my understanding:
Core Location is used to get your current location details
iBeacon is used to set your device as a Beacon for others to discover
Region Monitoring is used to monitor for when you enter a specific region
Am I correct in my assumptions? If not could someone please correct me. Also am I looking at the right kits that will help me achieve this?
What I would like to do is have a table of saved records that are triggered individually when they enter or leave there specified locations. (Do I use Region Monitoring for this)
Also how would I make this app still run in the background, once it is closed, and still trigger events (like the iOS Reminders App).
I have found a few basic tutorials that help me get my current location with CoreLocation but does anyone know of any other tutorials that might help me out? Or know themselves how I can go about accomplishing this.
Would really appreciate some help. Thanks!

I think that the best choice for your app is using Region Monitoring:
You could register up to 20 regions;
iOS will launch your app automatically if iPhone enters the observed region.
From Apple docs:
If a region crossing occurs while your iOS app is not running, the
system automatically wakes it up (or relaunches it) in the background
so that it can process the event. When relaunched, all of the regions
you configured previously are made available in the monitoredRegions
property of any location manager objects you create.
An app can register up to 20 regions at a time. In order to report
region changes in a timely manner, the region monitoring service
requires network connectivity.

Related

React Native iOS app restart on reboot

I want to create an iOS app using React Native. One of the primary features of the app is that it runs constantly in the background. It also requires using GPS btw (in case that is important).
I have had a number of devs tell me its not possible to do this for iOS, however I have read that it is do-able.
Is this possible to do in the iOS environment? Mainly, if the app is running when the phone is powered off, can you make it open when the device is restarted without the user opening it?
I should say that I am a RN novice and any help is much appreciated.
If your app gets permission to get location while it's not in the foreground, then you will get periodic updates and some time to process it.
For example, if you are giving driving directions.
https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/LocationAwarenessPG/CoreLocation/CoreLocation.html#//apple_ref/doc/uid/TP40009497-CH2-SW10
If there is no good user benefit for you to get the location in the background constantly, you might be rejected. Apple suggests region monitoring instead
iOS supports the delivery of location events to apps that are suspended or no longer running. The delivery of location events in the background supports apps whose functionality would be impaired without them, so configure your app to receive background events only when doing so provides a tangible benefit to the user. For example, a turn-by-turn navigation app needs to track the user’s position at all times and notify the user when it’s time to make the next turn. If your app can make do with alternate means, such as region monitoring, it should do so.
I have no idea how RN wraps this behavior, but no matter what it does (or what a plugin might do), the core iOS behavior is how it is described in that URL.
I verified yesterday (at least on iOS 11.2 simulator) that automatically restarting the app (and the location tracking) after phone reboot works.
The key point is that startMonitoringSignificantLocationChanges needs to be on to wake up the app after reboot. For me the difficult part was figuring out when to turn it on, because I couldn't find a reliable way to detect when the phone is being rebooted or run any code at that point. However, based on initial testing it looks like startMonitoringSignificantLocationChanges is independent and doesn't negatively impact the usual location updates, so now I just leave it on all the time and toggle startUpdatingLocation / stopUpdatingLocation on top of it based on Core Motion-detected activity.
Otherwise requirements are the same as for any location tracking on the background, i.e. handle permissions and don't process too much. Apple documentation explains how to detect that the app was relaunched by a location event.
Here's a react native module which basically helps you achieve what you're describing: https://github.com/transistorsoft/react-native-background-geolocation

How to avoid battery drainage if the app is using GPS even when the app is in background

I have to build an app that will have the following features :-
A way to add users and their data in a database. (which will be parse)
The app will access the location updates of the user (say after every 10 minutes or when the user has moved a significant distance). This will be done even when the app is in background. These locations will then be updated to the parse database as and when the new locations are received.
I am a beginner, so any suggestion to how i should approach this will be appreciated. Most importantly, i have the following problems :-
The app will also run in the background and will regularly use GPS. This will drain a lot of battery. How can i avoid this? (The precision of the locations are important)
The app will regularly update these locations to the parse database and will have to make regular API requests which will add to the cost. How can i minimise this?
From your description what you want is "significant location change" monitoring, which is built in to CLLocationManager. Instead of running continuous location updates, you tell the location manager to send you "significant" changes in location, i.e. when the user has moved some undocumented "significant" amount. It's specifically designed to minimize battery drain, so you don't need to bother disabling and reenabling it. Instead iOS makes sure you're using as little battery as possible to get the updates.
The CLLocationManager discuss the approach in some detail, but the basics are:
Once you've created your location manager, tell it to start significant location updates:
locationManager.startMonitoringSignificantLocationChanges()
Location changes are provided to the delegate via the same locationManager(manager:didUpdateLocations:) method used for continuous location updates.
iOS will wake your app up to let it process location updates.
You'll want to periodically update your location rather than leave GPS on continuously. Here's a tutorial covering CLLocationManager you may find helpful.
Without specific code, I can't give you a specific answer, but generally speaking you'll want to periodically turn on CLLocationManager, get your location, and turn it off again until the next update. You can also configure the accuracy of CLLocationManager--the more specific your location, the more battery power is required.
Here's another tutorial on CLLocationManager to take a peek at, too.

How does iOS Google Map detect I am entering a car?

The latest iOS Google Map application(currently of version 4.9.0) has a very nice feature, but so far I can not figure out how this is possible.
The feature is: whenever I am entering my car, try to drive somewhere, Google map will send me a notification to my phone, guess where I am going, giving me an estimate of the traffic, even when the phone is in locked state, and the Google map app hasn't been used for days. A screenshot is provied as following:
This is quite amazing to me as an iOS developer. How can it live in the background and detect I am entering a car with such accuracy?
One of my guess is, Google map is using significant location change API. By using this way, the app can be waken in background mode, but, there is still no guarantee it is waken when I am entering my car. And I have already written a test app using this mechanism, although it can be waken in the background, but the timing is not correct, failed to detect I am entering a car or not.
CLLocationManager Class Reference
If you start this service and your app is subsequently terminated, the system automatically relaunches the app into the background if a new event arrives. In such a case, the options dictionary passed to the application:willFinishLaunchingWithOptions: and application:didFinishLaunchingWithOptions: methods of your app delegate contains the key UIApplicationLaunchOptionsLocationKey to indicate that your app was launched because of a location event. Upon relaunch, you must still configure a location manager object and call this method to continue receiving location events. When you restart location services, the current event is delivered to your delegate immediately. In addition, the location property of your location manager object is populated with the most recent location object even before you start location services.
Any suggestion and help appreciated.
One comment from #alexkent points out my mistake. This is Apple's Maps.app, not Google Maps. All credits belongs to #alexkent.
That notification is from Apple's Maps.app not Google Maps. A new
feature in iOS9 (which you must be running) is the ability to detect
when you are in your car. I imagine this is done by detecting the
Bluetooth signal from the car radio (I have not checked this). I do
not believe there is developer API available for this feature.
#alexkent is right. It works using bluetooth and there is no public API for that. If you close your bluetooth this stops happening.
Geofencing and in general Geolocation accuracy is not that granular.

Tracking location in background in iOS: standard location service vs. region monitoring

I need my app to know user's position at all times, even in background. My app receives a set of regions of interest I need to check if user crosses. I don't know the size of those regions beforehand, so I need to listen for location updates with high accuracy. Then, I discard the use of the significant-change location service. Moreover, I need to call a service regularly for data updates even in background as well.
So, it seems that there still are two options:
1) enabling the background mode for location services and using the standard location service
2) region monitoring, which doesn`t seem to require enabling any background mode
However, I don't find information about the accuracy of region monitoring. My question is: taking into account that I have the coordinates of the regions I want to detect if the user is in, that I need high accuracy, and that I need to perform regular async services calls in background if location services are enabled (with a timer), what option should I choose?
Another thing: my app has to support iOS 5+
Thanks in advance
First of all, I would like to suggest you to drop iOS 5 from your support. If it is the customer's request, I would like to suggest you to convince them to drop this. See: The market Share for iOS. The market share for iOS 5 and below is less than 2%, the time spent to optimize for those devices are not worth it.
Personally, for the app that I developed in the last 6 months, I only support iOS 7 and above.
As for your question, you can choose both the options. They are not conflicting with each other. The app that I developed have location service in the background that sends the current location of the user to the server every minute and the same app also has region monitoring for crime zone. The user will receive notification when he/she enters the zone.
For how to keep the app active in the background, you may check this thread: Background Location Services not working in iOS 7
For Region monitoring, you may check this thread: Region Monitoring Glitch on iOS 7 - Multiple Notifications at the same time I posted a bit of code related to a glitch.

iOS: Notify a WebService of location change (using Significant-Change Location Service)

I'm developing an app that allows me to track the device's location, the idea is that the app notifies every few hours our servers of the current location so I can send relevant push notifications to the user.
This should work even if the app is not running (the app should be awakened by the OS).
I was reading the Location Awareness Programming Guide (http://developer.apple.com/library/ios/#documentation/userexperience/conceptual/LocationAwarenessPG/CoreLocation/CoreLocation.html) and I think the Significant-Change Location Service would help me accomplish this, however the guide mentions this:
it should do minimal work and avoid any tasks (such as querying the
network) that might prevent it from returning before the allocated
time expires.
If this is the case, I don't think I will be able to notify our servers of the location change.
I'm assuming this is possible because there are apps like "Find My Phone" that have to get the updated location of the devices every once in a while.
If this is not the right approach I would appreciate any pointers to info on what should I do to get this working.
Thanks

Resources