Is there any way to start applicaiton when device restarts .
I mean - my appliaction is trying to get location when the application is running in background, but any how if user is restart the device then application will not provide any location updates.
So is there any way to keep application running even though the device is restarted ??
Thanks in advance.
No, iOS does not provide anything like an autostart functionality. There might be a way on jailbroken phones, but if you aim for the App Store you'll have to design your app/service that you can live with this limitation.
Edit: I stand corrected. If you set the voip value in the UIBackgroundModes key of your Info.plist, your app does get restarted after a device reboot. According to the documentation:
voip:
The application provides Voice-over-IP services. Applications with this key are automatically launched after system boot so that the application can reestablish VoIP services.
Related
I have application which is sending tracked data to our hosted server whenever location manager called in background. Its working fine normally.
But issue is when user switched off the iPhone and turn ON it back application is showing GPS icon but application is not giving response.
PS: User have not touch the app or start after restart the app.
Is it possible to get the response from the app after restart the device?
That is because the app is not active after restarting the iPhone. You could add the voip key to UIBackgroundModes as detailed in this SO post (and a sample app on GitHub) to start your app again after restarting the device. However, if you use this app only for tracking the location, Apple will likely reject your submission for making use of the voip-key.
If you use region monitoring, then your app will be automatically started in the background when a user enters or leaves a region, even if the device is turned off and back on. Use region monitoring, see this answer on SO.
Applications can register for significant location changes.
(Recommended) The significant-change location service offers a
low-power way to receive location data and is highly recommended for
applications that do not need high-precision location data. With this
service, location updates are generated only when the user’s location
changes significantly; thus, it is ideal for social applications or
applications that provide the user with noncritical, location-relevant
information. If the application is suspended when an update occurs,
the system wakes it up in the background to handle the update. If the
application starts this service and is then terminated, the system
relaunches the application automatically when a new location becomes
available. This service is available in iOS 4 and later, only on
devices that contain a cellular radio.
From https://developer.apple.com/library/archive/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html
An app can be relaunched when the location changes. However, can it be started automatically when the phone is started? The documentation isn't quite clear.
The service will start when the user launches your application, and terminate if it is closed. The service will remain running if the application is running in the background.
Developers cannot integrate services into the OS, for security purposes.
No, you cannot have your application run automatically when the phone is started. In addition, if the user starts your application manually and puts it into the background, the system may eventually kill it when it needs the memory.
"Including the voip value in the UIBackgroundModes key lets the system know that it should allow the app to run in the background as needed to manage its network sockets. An app with this key is also relaunched in the background immediately after system boot to ensure that the VoIP services are always available."
check iOS docs here
Although if you do this for an illegitimate reason I am guessing your app will either not get approval or get booted quickly.
Saw an app called PhoneRecover on the AppStore.
They advertise the following:
PhoneRecover will automatically restart after a reboot on the iPhone 3GS and the iPhone 4 running iOS4.
How is this possible? What APIs are used to auto-launch an app after a boot?
It's built into multi-tasking. "Backgrounded" apps are still in background after a reboot. Presumably the app does some work to re-instantiate itself and get its state going again the first time Core Location hits it in the background, but there's no other magic happening here. Any background-aware app will survive a reboot in a backgrounded state.
I wouldn't count on this. I was running MotionX GPS and let the battery run completely dead. Upon restart MotionX was no longer running, broadcasting my position or tracking my position. The broadcast option is persistent too (survives app restart).
I'm reading through the multitasking documentation, and it has a few references to apps which launch directly into the background state, never entering the foreground state. Is this really allowed for regular apps? Can anyone give me an example of an app like this?
VoIP apps are the biggest one to use this feature. Basically a VoIP app can register itself with the system to be notified when network traffic is intended for it at which point the app takes over handling the incoming traffic (i.e. receiving a call). Skype and Viber both use it.
From the iOS Developer Library (emphasis mine):
Including the voip value in the
UIBackgroundModes key lets the system
know that it should allow the
application to run in the background
as needed to manage its network
sockets. An application with this key
is also relaunched in the background
immediately after system boot to
ensure that the VoIP services are
always available.
The significant location changes backgrounding service also allows an app to be updated with the new location even if it's not running.
Other than those two cases, an app can't do anything from a terminated state until the user launches it.
When you use location manager with significantchange notification, App gets backgrounded automatically if the app is killed, when there is a location event
How does Apple do polling of a phone's location remotely? Is there any API that allows an app developer to do the same with the SDK?
My guess is that they are private, undocumented and probably un-callable api's.
I couldn't imagine the huge security implications of having an external party/app be about to poll a phone location without the users consent.
An iOS device already maintains a connection to one of Apple's push servers if push is enabled, and the server has to know the device on the end of the connection (to determine the push notifications to deliver to it). The easiest way to build on this is to have the server say "tell me where you are!" as a push notification.
The device also hits Apple's servers for other reasons (App Store updates, captive login page detection), but it's less likely that the server can identify the device in these cases.
That said, you can do this with the user's consent:
Make your app a background "voip" app (<key>UIBackgroundModes</key><array><string>voip</string></array> I think)
At app launch, check that you can retrieve the current location (I'm not sure what happens if you do this while your app is backgrounded).
Maintain a "voip" connection to your server.
When the server asks the device for its location, ask Core Location for the location again and send it to the server. (I think you also need either "location" in UIBackgroundModes or you need to keep the connection active, possibly in both directions; the former may be easier.)
You won't be able to stop the "location services" icon from appearing in the status bar. The usual multitasking caveats also apply (your app can be killed if the phone runs out of memory; "voip" causes your app to be relaunched sometime later though).
I'm pretty sure if you do the "voip trick" your app will be refused from the store. It is only allowed if your app is actually a VOIP app, not just using it as a technique to circumvent background processing restrictions.