So my question is whether an app, which is running in the background, can access the device's location information and save it in the heap or send data to a server?
I know it would have to do something with the delegate but I'm not sure a process of this complexity can be done while the app is in the background
Yes, you can!
In the Location Awareness Guide of apple its is described that application that need to receive GPS in the background have to set a specif value:
Set key location in the UIBackgroundModes array of your Info.plist file.
Yes. You can do it.
By setting the proper key-value in info.plist file, your application will able to fetch locations even when its in background.
Using ASIHttpRequest (Link), you can upload the data using web service.
For that, create the object of ASIHTTPRequest and keep the value of shouldContinueWhenAppEntersBackground to TRUE.
Related
Can you, in Swift get a change notification when a document in the apps's iCloud Drive container changes?
For example I am testing a simple concept where I am storing all app data as a json string in the app's iCloud Drive container and I am loading it when the app launches. I can retrieve and save the json string on demand on multiple devices, but I am wondering if there is a way to get a change notification sent to an app when the file is changed on another device.
If so, some direction would be appreciated.
If you are using UIDocument, you can register for UIDocumentStateChangedNotification (for a particular document), otherwise if you are looking for changes in the App's iCloud container you need to use NSMetaDataQuery which is described in Discovering an App's Documents in Document-Based App Programming Guide for iOS
I’m developing an application for iPhone that require server to be always aware of the user location. Does iOS have a feature whereby application (or iPhone device) keep reporting it’s location to external server?
Take a look at the "Tracking the User's Location" section in the iOS App Programming Guide. It tells you how to retrieve location data in the background. In this case, you probably only want to get significant updates.
You should be able to use startUpdatingLocation, then do whatever you want (e.g. a POST request) in the delegate.
I wonder if it is possible for iPhone 4:
I have a server which sends queries about the location of the phone (irregularly) via an iPhone app. Customer can choose a setting that allow the phone to send back geotag information (longitude and lattitude) in the background (without customers doing anything).
If it is possible, how should I do it? If not, what is the closest alternative available?
Thank you.
Yes, you can do this. You have to set the UIBackgroundModes flag in your Info.plist to indicate that you execute in the background.
See: Information Property List Keys
Note that running the GPS from the background will severely impact battery life. In addition your application may be terminated at any time if the system needs the memory.
I can get the current location of my iPhone but I was wondering if it is possible to call my methods when application is in background and pop-up message(may be using local notification?) if user has reached at particular location.
Thanks.
Yes, this is possible. A local notification is also an excellent solution.
All you need to do is to set the flags for background position updates in the app plist. Then, in the callback methods for the location manager, perform the distance and/or location tracking logging and fire a local notification.
How is it possible to keep CLLocation updating in the background. I believe you need to register the application to do this in the Application delegate but I can not find a reference to this anywhere?
Here is a link to the relevant documentation:
https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html#//apple_ref/doc/uid/TP40007072-CH4-SW20
in particular, see this paragraph:
An application can declare itself as needing continuous background location updates. An application that needs regular location updates, both in the foreground and background, should add the UIBackgroundModes key to its Info.plist file and set the value of this key to an array containing the location string. This option is intended for applications that provide specific services, such as navigation services, that involve keeping the user informed of his or her location at all times. The presence of the key in the application’s Info.plist file tells the system that it should allow the application to run as needed in the background