Location Services in iOS 8: Background Modes - ios

There is a Background mode called Location Updates.
If I include the CoreLocation framework, and in my info.plist include the key NSLocationAlwaysUsageDescription and the value being a String with whatever I need to use it for, do I need to tick the background mode for Location Updates? Can I just use it upon authorization? I've tried looking up iOS 8 guides for Core Location as I've never used it before, but nothing touches on this. I don't know what it is used for if you don't have to tick it for getting location in the background.

When you get authorized for the AlwaysUsage, you can get location whenever your code is running. But it won't run on background unless you have activated an appropriate mode for that.
Apple's Programming Guide describes the philosophy of background modes pretty well.

Related

can we get location updates in IOS swift in a regular intervel of time even when app is not running in foreground

I want to get location updates of the user in a regular interval of time even if the app is not running in foreground.
In most of the articles i have read, they said that the OS will forcefully stop or suspend the background service the app have started.
What i need is the app should regularly check the user location and when that location becomes greater than say 10Kms the app should trigger a local notification.
We were able to do the functionality correctly when the app is ran again by the user. But it wont work in background. And if we inegrated it as a background service , then it is causing the app to crash. :(
this part caught my attention after a long time of search
https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/LocationAwarenessPG/CoreLocation/CoreLocation.html#//apple_ref/doc/uid/TP40009497-CH2-SW8
As far as I understood, they say that the OS will wakeup the app to get the current location when it senses a change in location.
But I didnt get any helping tutorial to accomplish the same
These are the tutorials which I refered
Periodic iOS background location updates
How do I get a background location update every n minutes in my iOS application?
Getting user location every n minutes after app goes to background
iOS Not the typical background location tracking timer issue
iOS long-running background timer with "location" background mode
What i need is preferably a background service or something which does the job done which check of the current location calculate distance and makes a local notification.
But as far as i know all the background services will be suspended or killed by the OS within some time after the app is gone in background.
Please guys I am desperate, Its been 2 weeks i am on in its tail.
Building the same for Android was a piece of cake actually.
Any help ???
You can get background location updates easily, you need to enable "Location updates" under "Background Modes" section in capabilities.
You also need to request for Always Authorisation and finally add this
if #available(iOS 9.0, *) {
locationManager.allowsBackgroundLocationUpdates = true
}
Make sure "Location updates" is activated else the above code will lead to a crash.
Also, write the CLLocationManager Delegate Methods in your AppDelegate class as this would increases chances of those methods being called as mentioned on Raywenderlich Background Location tutorial

No Background Updates on iOS 9

I am implementing an App with continuous background updates on iOS 9. Even with allowsBackgroundUpdates set to YES, AlwaysUsage Description and with proper authorisation i am not getting location updates continuously. I am using Standard Location Services and Significant Location Services but not receiving any location updates when App is in Background. (App is in background/suspended but not terminated). Can anyone let me know if i have missed anything? Thanks in advance.
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.) Examples of apps that might need this type of location updating are fitness or turn-by-turn navigation apps

Play background music would be rejected by Apple Store?

I produced a pedometer program in ios.I want it can work in the background,But I found it would interrupt finally.So I add a AVAudioPlayer and play a silence music when in the background and it works right.
Now I want to submit to the App Store.I worried that I would be rejected.can anybody tell me about sth?
If this way doesn't work,How can I run a pedometer in the background?
(ps)I need to support the device without M7
Yes you will be rejected. You cannot do tricks like that just so you can have your application run in the background. It's like declaring your application as a VOIp app just so you can run background processes.
I suggest you have a legitimate feature that requires the background process otherwise your application will be rejected.
Have a look at this link and search for the heading UIBackgroundModes to see the 6 UIBackgroundMode keys:
UIBackgroundModes (Array - iOS) specifies that the app provides specific background services and must be allowed to continue running while in the background. These keys should be used sparingly and only by apps providing the indicated services. Where alternatives for running in the background exist, those alternatives should be used instead. For example, apps can use the signifiant location change interface to receive location events instead of registering as a background location app.
I do feel that you can have your application run in the background if you use some location services in your application. Then, quite possibly, could you register your application under the location's key:
The app provides location-based information to the user and requires the use of the standard location services (as opposed to the significant change location service) to implement this feature.

What happens when app registers for location updates?

I just wanted to know what happens, when i select app registers for location updates under "Required background modes" in Xcode for an IOS app.
VOIP provides aliveTimeOutHandler for specific duration. In same way, whether location services provides any aliveTimeOutHandler method? I am using IOS7
When your app registers for location updates it will periodically check for location changes when in the background. Of course this is just a switch in project settings that enables that bground mode for your app. You need to actually implement the background task (write some code). You can see the accepted answer here on how to achieve this.

iOS: Continous Background Location Updates

I need to work on an app where accurate location updates are needed to run on the background.
I can see this paragraph from the iOS App Programming Guide:
An app that provides continuous location updates to the user (even when in the background) can enable background location services by including the UIBackgroundModes key (with the location value) in its Info.plist file. The inclusion of this value in the UIBackgroundModes key does not preclude the system from suspending the app, but it does tell the system that it should wake up the app whenever there is new location data to deliver. Thus, this key effectively lets the app run in the background to process location updates whenever they occur
However, I do not quite understand what happens in the background. Does the app keep the same accuricy measurement determined in the foreground location services? if so, how long does it keep up running in the background?
It does keep running in the back ground, till it is suspended by the iOS because of lack of resources. As long as it is in the back ground. A simple example would be for you to NSLog the location and then connect the iPhone later to your XCode and look at teh console. Not sure how long of an operation you can perform though, but I am pretty sure you can do some basic core data insertion.
Take a look at this cool tutorial http://mobile.tutsplus.com/tutorials/iphone/ios-multitasking-background-location/
Which gives you a project which you can play around with.

Resources