Using both standard and significant-Change Location Service - iphone

I like to extend my app which is using Standard Location Service with the capability to notice the app when an Location change happend even when the app is not running or in Background.
Apple proposes for this the use of the significant-Change Location Service, which would be ok to save battery power and the accuracy would be fine for me.
But is it possible to use both the standard and significant-Change Location Service together in one Project ?

Found a solution to implement this with the help of the Apple Developer Forums. I did the following:
Specify location background mode
Use an NSTimer in the background by using
UIApplication:beginBackgroundTaskWithExpirationHandler:
In case n is smaller than UIApplication:backgroundTimeRemaining ,it does works just fine, in case n is larger, the location manager should be enabled (and disabled) again before there is no time remaining to avoid the background task being killed.
This does work since location is one of the three allowed types of background execution.
Note: Dont loose time by testing this in the simulator where it doesn't work, works fine on my phone.

Related

When Standard Location Service and Significant Location Changes are used together, What`s happen?

Simultaneous use of Standard Location Service and Significant Location Change.
I’m trying to develop App using Location Information.
Can Standard Location Service and Significant Location Changes be used together?
I currently use Standard Location Service in the main.
However, Even when the app is in not running state, I want to use a location service in my app.
So I am trying to use not only Significant Location Changes but also Standard Location Service.
Then some questions came up,
When Standard Location Service and Significant Location Changes are used simultaneously, what`s happening?
Do the two functions work simultaneously?
Does only one function work? Assumption
If only one function works, which one will work?
If the two functions work simultaneously, Is there a problem with battery consumption?
The significant-change location service offers a more power-friendly alternative for apps that need location data but do not need frequent updates or the precision of GPS. This can run when the application is in foreground, background or not running state. So if your application does not need very frequent locations updates then you can use this. FYI it delivers location updates to your app only when the user’s position changes by a significant amount, such as 500 meters or more.
Standard location service will work when the application is running in foreground state and background state(when the back ground mode for location is enabled) only. As soon as the application will get killed(by user or iOS) the standard location service will stop working.
For this you have to set the significant location change service which will wake your application in the background and provide the location updates to your application.
So you should analyse the functionality in your application and check the required frequency of the location and decide your implementation.
Both do not work simultaneously. Only one will work according to the application's requirement and application state.
Both services will work according to the previously mentioned.
They do not work simultaneously. But if you choose significant location changes to implement then it will be far more battery efficient but the location fetching accuracy will be very low.

Multiple GPS apps running in background on iPhone?

Is it possible to have more than one application running on the iphone accessing the GPS (simultaneously)?
Yes. For example, I use RunKeeper and the Maps app at the same time. Your app will need background privileges for keeping the GPS running. Here's the docs:
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.
https://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html#//apple_ref/doc/uid/TP40007072-CH4-SW24
Yes, but in practice it doesn't work very well. For example I have tried many times to use Strava and Pokemon Go at the same time. Usually one or the other will not work. Sometimes Strava reports the full mileage (it's my running commute), but then Pokemon Go will only credit me with 4k (when I ran 8 miles). Similarly, when Pokemon Go is working, Strava will lose GPS and lose data for miles at a time. In that case Strava reports that I ran about 4-5 miles out of the 8.
This is on an iPhone 6 Plus.

Programmatically change Required background modes

I have an app that need Location Based Services in the background.
So in info.plist I setrRequired background modes to "App registers for location updates".
and everything works fine.
My question is, how can I disable it running in background?
Is it possible to add an option and let users set it on/off?
As I know info.plist can not be change programmatically
so how can I do this?
The key is the description - it supports registering for location updates. So all you should have to do is tell your location manager to stop updating when the app goes into the background (or before) and it should then not be using location updates in the background.
There is no way to re-define the info.plist abilities of the app at runtime.
Traditionally (and pragmatically) you would set up your location manager to -startUpdatingLocation while your app is in use. This will drain your battery pretty quick if you leave it running full time. Typically you would call this, get the information you need, or update information, the call -stopUpdatingLocation. This puts everything to rest, no more battery drain.
When rolling over to the background, you have very limited options for accuracy if you still want to preserve battery life. The main one is -startMonitoringForSignificantChanges. This location update relies primarily on cell tower hand offs and triangulation. So if your user isn't moving large distances or is in an area with limited cell reception, don't expect this background mode to work very good.
You other background option is -startMonitoringRegion. This allows you to create a circle based region around places and get notifications when you -enterRegion or -exitRegion. These all have to be set up before entering the background. They do have the added benefit of better location updates. WiFi changing, cell tower handoffs, and even other apps using location updates. The OS grabs all locations updates and funnels them down and makes them available to any regions registered with the OS.
You still have the option to run location updates live in the background, but your users will not be thankful that they have no battery after 30 minutes of use.
Good luck. There are plenty of examples how to achieve all of these on SO and the web. The trick is finding the right combination that will work for you. Good Luck.

Is it possible to run application in background forever in iphone?

I know with ios 4 it is possible to run application in background as per this documentation
http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/BackgroundExecution/BackgroundExecution.html
this documents states that if application updates user's current location in background continuously then it is possible to run it in background.but is it necessary that we have to use only CLLocationManager for updating current location?can we user other apis like google latitude apis for updating current location?then also it is possible that application is able to run in the background forever?
As far as I understand from the document you posted, if you define the UIBackgroundModes with a value of location in your info.plist, "the system should allow the application to run as needed in the background". So, the first answer is yes, the application can run in the background and it will run indefinitely (up to battery life). This could be easily checked, actually.
Anyway, it seems to me that this kind of functionality is "reserved" to GPS-like apps and that Apple is really concerned about its usage:
For applications that require more precise location data at regular intervals, such as navigation applications, you need to declare the application as a continuous background application. This option is available for applications that truly need it, but it is the least desirable option because it increases power usage considerably.
so, I understand that Apple will screen really thoroughly all apps that activate this mode in order to assess if they really need the continuous update or do not (and in this case, possibly, the app would not be let in into the App Store).
Now, to answer the second part of your question, I think that one way that Apple will know if your app really complies with the rules, is its usage of CLLocationManager. The risk is that if you use another service, then Apple could think when reviewing your app that you just need background time without needing to constantly update the location.
But this is just a guess...

iPhone background network connection by timer

I need to write an application, that every 10 minutes it should be awaken from suspended mode, get user location via gps and send this information to the server by network.
Depending on the response it should return to the suspended mode or show local notification to the user.
Is there a way to do this on iOS 4?
I've tried different approaches, but the only working for me was to start monitoring user location in backgroind and declare the application as location background application. In that case it worked in background and has a network connection. But this approach takes a lot of power and not accepted cause application should work 24/7.
May be there is a way to write some daemon that should work in background and wake my application every 10 minutes?
Apparently, Pastebot tried to do something similar with the 'audio' multitasking declaration (by playing a silent audiofile) and got rejected.. UNTIL they actually presented a option to the user to pick which audiofile they wanted to play. It's in the appstore now. :)
In this case: What is your reason for not wanting to use the location updates? If battery-usage is a concern, you can use the 'significant location changes only' option, after which you can temporarily change to a more accurate option.
This isn't possible outside of the method you have already tried.
The iPhone background task API will allow you to run a location service in the background.
There is no way to write daemons for the iPhone without jailbreaking, and that is not something I'm able/prepared to help you with.
App store friendly: use new APIs in iOS4, which allows u to make use of GPS location
Anti App store: create a daemon by adding a specific plist file to System/Library/LaunchDaemons/ and put ur app under Applications/. this approach requires a jailbroken iPhone however...
detailed information plz google the following keywords: daemon, multitask, background, etc...
cheers, Lloyd