NSURLConnection when app is in background - objective-c

I'd like to know if is possible to send asynchronous connections when an app is in background. The reason for this is because I need to send the user's location (get from Core Location) to update a database in a remote server everytime the location changes, even if the app is not in foreground.
Do I have to set any permission for this? Does Apple rejects apps processing connections when app is in background?
Thanks in advance!!

iOS provides multitasking API's i.e. even if your app is in background, some of its API's can be accessed. These services are -
Local Notifications
Background Audio
Background Tasks
Background Location
So you can definitely send location updates using CoreLocation when the app is not in foreground.
This link - iOS multitasking has code to start your service when app in background. Step by step instructions
Specify location background mode
Use an NSTimer in the background by using UIApplication:beginBackgroundTaskWithExpirationHandler:
In case x time is smaller than UIApplication:backgroundTimeRemaining it does works just fine, in case x 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.
SOURCE - How do I get a background location update every n minutes in my iOS application?

Here, from the apple documentation (http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html#//apple_ref/doc/uid/TP40007072-CH4-SW47)
There are several ways to track the user’s location in the background, most of which do not actually require your app to run continuously in the background:
-The significant-change location service (Recommended)
-Foreground-only location services
-Background location services
But you cannot send request, as the only possible things to do are :
-audio
-location
-voip
-newsstand
-Accessories & blutooth connection
So I guess you could store all your location, and send it with NSURLConnection once the app goes to foreground again

Related

react native background geolocation

I have a requirement to save user's geolocation when react-native app is running in background. I know react-native-background-geolocation is available for this but I don't want to use any third party tool for this. Is there a way I can fetch users current location even if the app is running in the background?
With the last Expo SDK 32 you should be able to to it.
We’re excited to announce that this release includes initial support for background location, a highly requested feature from many Expo users. You can now define simple JavaScript tasks in your app and register them to receive location updates in the background. Additionally, you can set up geofencing tasks that are triggered when the device enters or leaves specific geographic regions

WP8: Can this (PhoneApplicationService.RunningInBackground ) be used outside of location based app?

From this link below, it seems that your app can still get event when app is switched to background. But it seems it is used only for location based app. Can normal app do that? I had tried to declare ID_CAP_LOCATION but still Application_RunningInBackground not get called when switch to background.
http://msdn.microsoft.com/en-us/library/windowsphone/develop/microsoft.phone.shell.phoneapplicationservice.runninginbackground(v=vs.105).aspx
The app doesn't execute in background, unless it is continously tracking the location.
This section lists the conditions under which the operating system
will deactivate an app running in the background....
The app stops actively tracking location. An app stops tracking location by removing event handlers for the PositionChanged and
StatusChanged events of the Geolocator class or by calling the Stop()
method of the GeoCoordinateWatcher class.
Source: Running location-tracking apps in the background for Windows Phone 8
You will find complete info of how to run apps in background here:
How to run location-tracking apps in the background for Windows Phone 8

IOS Track User Location Map kit

How i can track user location using CoreLocation and MapKit? I place a point on the map. When the application is minimized to check whether the user has not reached the destination. If you reached to withdraw the notification.
Allow your application to run in background
In background, start your get geolocation thread active to get current location (on timely basis, after each 10 secs)
If the results gets approx. equal value (for ex.: 2 km. radius) to your location, then throw a local notification from that app.
To do all this, you will surely find documentation over web, topics are:
Allow your app to run in background
Fetch user's current location (Start this thread in background delegate method)
Match location
Fire local notification
These are the base flow points, hope this will help you for initial start up.

Long-running task performed in foreground is suspended when app enters background

When a user first opens my app, I need to download and install some content from a server before they can begin using the app. The problem is that this takes around 5 minutes on wifi, during which time the app goes into the background and the download is suspended.
Is there any way to either:
prevent an iOS app from entering the background whilst I perform my download
or continue peforming the task in the background (i.e. perform the task irrespective of whether the app is in the foreground or background)
Thanks
It really doesn't matter, if the user presses the home button it will go to background. Although you can do two things to mitigate the problem:
Use beginBackgroundTaskWithExpirationHandler, to give you a bit more time to download. Which you can read here.
Don't allow the device to become iddle, with [UIApplication sharedApplication].idleTimerDisabled = YES;. You can read more about that here.
Either way, the best thing you can do is to tell the user, that is an important download and he shouldn't quit the application.
Can't you include some or all of the content in your app bundle instead, and just download changes on first run?
I can't imagine this is a good first user experience, and it may not pass App Store review like this.
The only third party apps that are allowed to download in the background are newsstand apps loading issue content, and Apple are pretty strict about what they allow as newsstand apps.
You can't do what you want, in this situation. One way, and I think the best and only, is to resume your download when you app becomes active (returns to foreground state). Also, don't forget to register for connectivity notifications (Reachability class can be used for this purpose from this Apple sample app http://developer.apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.html). Good Luck!

how to delay application quit time in iphone sdk?

I want to register my app for push notification when my application terminates so i think if i delay my app quitting time it could be possible.Does someone knows how to delay application quitting time? I think this method
[self performSelector:(SEL)aSelector onThread:(NSThread *)thr withObject:(id)arg waitUntilDone:(BOOL)wait];
will do my job but i don't know how to use this method if someone knows please tell.I need to send some data to a server along with registering for Push Notification when my app quits.
I can't imagine why you would want to do this. If it were even possible it would be extremely annoying for a user to tap the home button and the app to take x amount of time to shut down. This time 'x' being dependent on the server connection creates even more user headache.
Apple have the home button exit apps immediately for a reason.
If you want to register the Push Notifications like you suggest, do it while the app is running. If your worrying that they won't be properly set if the user exits prematurely... don't.
As users, we all know there are sometimes consequences of exiting a program without giving it time to save your settings.
For push notification it is better to register when the app first starts and then send the push token to your server in the background. However, if you have a good reason why you need to do the registration just as the app terminates, I believe you can do this if you are using iOS 4. iOS 4 has a new feature called "task finishing" that allows an app to stay running for a few minutes after the user closes it so that it may finish up any tasks it was in the middle of (such as saving data).