Background location iOS - ios

I need to capture device location independently if app was killed, I have enable background modes location updates and background fetch also I have on app delegate the locationManager with startMonitoringSignificantLocationChanges. Currently I print each location update received.It works perfectly with app on foreground and when app is minimized, but when app is closed (double click Home button and remove) I dont receive updates. According to some forums and sites app should be called on background with each new location update but it dont works.

If the app is closed, it can't report location. The only thing that apps can do while closed is show notifications.

If the app is force closed by the user it will not be able to continue to update the users location in the background, there is nothing that works around this.
from the app life cycle documentation: https://developer.apple.com/library/content/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/TheAppLifeCycle/TheAppLifeCycle.html#//apple_ref/doc/uid/TP40007072-CH2-SW6
In addition to the system terminating your app, the user can
terminate your app explicitly using the multitasking UI.
User-initiated termination has the same effect as terminating a
suspended app. The app’s process is killed and no notification is sent
to the app.

Related

iOS - System Alert Location use in Background

Sometimes I get an alert message, reminding me that my App is using the location service in the background.
If I read the Official Documentation, in the Give apps permission to use your Location section.
Other apps will ask for access to your location even when the app isn't in use. When you allow an app to always use your location, iOS will remind you which apps are able to use your location after an app uses your location in the background.
We can clearly admit that this alert will only be displayed when your App is using your location in the background.
So why am I asking this question ? Because this alert message just appeared when I woke up my phone, with no Apps in Background (all Apps were swiped up from the double tap Home button).
Does Background has other definition or maybe I am missing something?
Your app can be woken up (launched implicitly) by the system depending on the background modes it supports.
Even if you manually kill it in memory by swiping up, it still can be triggered in background if there is an incoming data for it to process (such as silent notification with payload).

How to track user location when app is in killed state in ios

I want to track the user location in my ios app using objective-c even if app is in killed state/ suspended state.
please help.
Use Pushkit, when your server will send a remote notification then application automatically goes in background state.

Background transfer download task failed when app was closed

I have created background nsurlsession to perform download task. It worked well when the app was in background. However, download task seems to be canceled and failed when I closed the app (double click "Home" button and swipe up), and it made me to download from the beginning again when I relaunched the app. According to Apple document, background transfer works even the app is no longer running. Am I doing anything wrong?
From the NSURLSessionConfiguration Class Reference:
If an iOS app is terminated by the system and relaunched, the app can use the same identifier to create a new configuration object and session and retrieve the status of transfers that were in progress at the time of termination. This behavior applies only for normal termination of the app by the system. If the user terminates the app from the multitasking screen, the system cancels all of the session’s background transfers.
So, while background transfers will continue if iOS itself closes your app during the normal course of things, if you force the quit from the multitasking screen, it will kill all your transfers.
The app is not relaunched for background downloads when the user has force quit.
The iOS8 documentation for application:didReceiveRemoteNotification:fetchCompletionHandler: says:
Use this method to process incoming remote notifications for your app.
Unlike the application:didReceiveRemoteNotification: method, which is
called only when your app is running in the foreground, the system
calls this method when your app is running in the foreground or
background. In addition, if you enabled the remote notifications
background mode, the system launches your app (or wakes it from the
suspended state) and puts it in the background state when a push
notification arrives. However, the system does not automatically
launch your app if the user has force-quit it. In that situation, the
user must relaunch your app or restart the device before the system
attempts to launch your app automatically again.
In the first paragraph of NSURLSession documentation, we can observe:
This API provides a rich set of delegate methods for supporting
authentication and gives your app the ability to perform background
downloads when your app is not running or, in iOS, while your app is
suspended.
Now notice where it states:
or, in iOS, while your app is suspended.
It looks like only OS X applications have the ability to finish background tasks while your app isn't running.

Receive Notification of Battery State Change While in Background for iOS 7

So I'm building an app for iOS 7 which needs to display an alert automatically when the phone is plugged in to charge, even if the app is in the background.
The app also takes location into account, so I guess I can keep it receiving location updates. However, as far as I know, the app will stop receiving notifications about the battery state 10 minutes after it is put in the background.
Are there any suggestions as to how I can do this? I do not need to publish the app in the app store.
You can enable background fetch, and periodically check the battery state there. It's not as precise as you require, but this is the best you will get.

Other ways besides push to wake up an iOS app?

Has anyone created an iOS app reacts to events or triggers from external sources other than push (APNS)? For example, could an iOS app subscribe to a remote topic or queue? Or listen for HTTP or socket requests?
No.
Application could be launched if:
User tapped the icon
User selected the Push-notification/Local-notification
Application supports url-schemes and is launched while opening URL
Application supports view/edit of documents and user've selected your app to do this
If anyone has other ideas - feel free to edit or add comments.
App could run in background and have active http-connection/socket. But it couldn't be opened automatically.
In addition to user action and push/local notifications, an app can be woken by a significant location change, if the app has indicated that it wants to monitor such events.
See: CLLocationManager Docs
Look for a method called startMonitoringSignificantLocationChanges. If a significant location change occurs while your app is not in the foreground or isn't running at all, your application will be launched in the background, allowing the app to perform background-only operations (e.g. no view code will run).
The app will not launch into the foreground, however, if it is launched due to a significant location change.

Resources