I am developing a location dependent feature. The uses case is this:
User receives data and notifications based on their location.
Location is actually the city/town they reside in more accurately a
region based on the city.
Then they hop on a plane/train and go to another city. I want to
be able to detect that send them local notification to change
their location settings and if they accept to start providing them
data based on the new location i.e. city. Very important to this
part of the usage is the Airplane mode which is usually turned on
during the travel and then turned off when the user arrives at
their destination.
I thought region monitoring will be the perfect technology for that. However there is no way to find out if the user had gone outside the region when using Airplane mode. There will be nor crossing event and I am unable to request the state for the particular region. Also in that case if the app was terminated the system will not wake it up for crossing event because there is not one.
Is there a way to reliably handle that situation.
I also thought a replacement technology for my use case might be the Visit monitoring.
Thanks!
Related
I am working on an app that needs to call an API for every 100 meters the user walks for. I need to make the app work even if it is terminated by the system.`
I was thinking about region monitoring as it will work in the terminated state as well, but since it depends on Wifi and cell phone towers, it might not be accurate in my case as the user might be out on a remote hike.
For precision, standard location updates work well, but they don't work in case the app is terminated by the system.
So my question is can I use both standard and region monitoring services together? I can put a distance filter of 100 m and get continuous updates in the foreground and background from the standard location services and each time update the region for the region monitoring services, in case the app gets terminated, the region monitoring service can take over and send me location updates.
Are there any pitfalls with this approach?
I'm doing an app to trigger a local notification when a region is entered.
However, sometimes when the phone is locked, the notifications didn't pop up even I've been in the region area for a while. The notification popup will show only when the power/home button is pressed(phone still in locked mode).
In general, all seems to be working except that sometimes the notification will show only when power/home button is pressed to awake the phone although it is still locked.
Hope someone can enlighten me please! =)
According to the developer documentation. In core-location framework, two services can give you the current location information.
The standard location service is a configurable, general-purpose solution for getting location data and tracking location changes for the specified level of accuracy.
The significant-change location service delivers updates only when there has been a significant change in the device’s location, such as 500 meters or more.
You need to use standard location services to keep monitoring location in background
If your iOS app must keep monitoring location even while it’s in the background, use the standard location service and specify the location value of the UIBackgroundModes key to continue running in the background and receiving location updates. (In this situation, you should also make sure the location manager’s pausesLocationUpdatesAutomatically property is set to YES to help conserve power.)
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.
I need to get exact location (as much accurate as possible) in background while making a call to a phone number (The call will be made from app). As far as I understand from documentation, I can listen to significant changes of location in background. I am wondering how accurate is a significant update and when will it trigger.
I need the location where the call is made because it will be an emergency call. And it's not a good idea to listen to location in foreground and then make a call because it will be an emergency situation - call will be made immediately.
Is there a solution to get accurate location of user in background? What do you recommend?
Edit: Location will be sent to server immediately.
As for the accuracy, you can get accurate location in the background, under those conditions:
Getting Location Events in the Background
If your application needs location updates delivered whether the application is in the foreground or background, there are multiple options for doing so. The preferred option is to use the significant location change service to wake your application at appropriate times to handle new events. However, if your application needs to use the standard location service, you can declare your application as needing background location services.
An application should request background location services only if the absence of those services would impair its ability to operate. In addition, any application that requests background location services should use those services to provide a tangible benefit to the user. For example, a turn-by-turn navigation application would be a likely candidate for background location services because of its need to track the user’s position and report when it is time to make the next turn.
As for getting location during phone call, I didn't use it myself, but navigation apps like 'waze' do inform turns and navigation events during a phone call so I guess what you ask is possible.
If I understand your needs, you have 2 options:
If you think that the user will be static then simply get the user location right before the call is made. Or better when your app is lunched to make the emergency call.
If the user is moving then you can 'ask' to get background location events. Even then you should consider using 'significant-change location service' as you don't need more then the user location. The standard 'location services' are used for navigation 'Turn by turn' services.
*LAST COMMENT *
If your app is an emergency app you shold read the "Tips for Conserving Battery Power" in the previous link. you don't want your user battery to empty while tracking his location.
Can't you like add that flag in your app plist file to request Location Service to be running in the background mode.
Then in your app, when the user presses the "call" button, you can do your normal CLLocationManager didUpdateToLocation, right before you perform the call.
In your didUpdateToLocation method, you can record the user's location either in a TXT file written to the application sandbox Library/Cache folder or you can use NSUserDefaults.
Note: I've written an app that records the user's GPS location as they drive even when the user presses the lock screen, so I am confident your app can write the GPS coordinate to a TXT file even when the app is minimized, as long as you start your location manager.
Registering for significant change location the app only receives coarse location updates (if the device moves from cell to cell), however according to this post
If background applications can't launch automatically how does Cardcase launch on a location change?
its also possible to use startMonitoringForRegion:desiredAccuracy: and have the app woken up when a location change occurs.
Presumably the desiredAccuracy can be pretty fine, so does this imply its a back-door way of registering for significant changes to location but with a fine grain?
Is it permissable by the app store therefore?
In my testing I have observed that the region monitoring is sometimes not very accurate, i.e If I drive past a region I might not get any indication of having entered or exited the region. (under the hood it might be using something similar to significant location change)
Also the desiredAccuracy here is really the buffer (in meters) around the region where notifications should not be generated , this is to prevent multiple notifications if you are at the edge of a region.
Not really. You have to specify a specific region, and you only get sent notifications when the region is entered/exited.
It's the same mechanism that the Reminders app uses for sending reminders, they create a region around the location, for instance work, and register for region notifications.
While it might theoretically be possible to create lots of little regions next to each other, it's not really intended for that and will probably cause problems down the line.