Load the iphone app automatically when phone boots - iphone

I am doing a tracking kind of application for internal use of an organization and do not wish to submit it to app store.
What I am doing in the application is I am tracking the phone calls, messages etc.
My app runs in background once I start the app manually and keeps on running in the background until I close the app or the phone is switched off.
The thing that I want to add to my app is, I want to load the app automatically when the phone is switched on again.
Any idea or guidance will help. Suggestion for use of private apis is also welcome.

In private api, in file SBApplication.h there are all methods that you need.
In particular:
[...]
-(BOOL) _shouldAutoLaunchOnBoot:(BOOL)boot;
-(void) autoLaunchIfNecessaryOnBoot:(BOOL)boot;
-(void) _cancelAutoRelaunch;
-(void) _relaunchAfterExit;
[...]
etc, etc...
hope this helps.

As far as I can understand you can do it by registering your app for significant location changes. If an app registers for significant location changes, as soon as your cellular phone moves to a new tower, app receives an update. If the application is suspended when an update occurs, the system wakes it up in the background to handle the update.
So if you close the app and turn of your phone, as soon as your phone will restart it should get an update and it will force your app to run in background mode.
For more info read iOS programming guide: http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/BackgroundExecution/BackgroundExecution.html
Hope it helps

Related

Location Tracking

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.

Application doesn't launch with location key after a significant location change

My application uses the core location also after the application terminates with the method startMonitoringSignificantLocationChanges in CLLocationManager class.
My application launches with a location key in iOS 5 and 6 in the method:
- (BOOL) application:application didFinishLaunchingWithOptions:launchOptions;
in AppDelegate class and everything works well.
But in iOS-7 betas the application doesn't launch with a location key after a significant location change.
Has anybody encountered this problem?
I tried it on a simulator and in the device.
Thanks for the help.
I have the same problem in my app, when the app was terminated by user from app switcher.
But it does launch with location key if it was terminated by OS for low memory or other reason.
It is the expected result from iOS7 unfortunately. An official apple response I got from one of their evangelists:
If a user swipes up in the app switcher then the OS will not launch
the app unless explicitly told to do so by the user. So no, SLC will
not be launching the app, nor will silent notifications. The only
thing that will launch the app at that point is the user tapping the
icon. The intention here is that the user has expressed their choice
of not having that app running any more for any reason, so we honor
that. In this situation, there's really nothing that you can do. The
next time the user launches the app you can let them know that some of
the data may be missing, although you really cannot tell whether
there's missing data or not (i.e. you might have been killed by the OS
in the background and the user may not have moved thereby not
triggering any SLC notifications). My suggestion would be to gather
the data you can within the policies of the OS and if the user has
manually killed the app then respect that wish and don't do anything.
By all means, feel free to file a bug report if this change in
behavior winds up causing problems for you or (especially) confusion
for your users.
Attach link to Apple DEV forums:
https://devforums.apple.com/message/882691#882691

Keep infomed for Device location will Application in Backgroud

I'am developing an application that keep a WebService informed for device location each 5minute (for exemple) :
So when the application leave the foreground execution and enter background I have to lunch a timer who
1 - Update the device location
2 - Send the location to a web service
How can I perform this action ? Or do you know any code exemple that I can follow to achieve this design ?
Thank you for your help !
Doesn't look like anyone gave you a solid answer, so allow me.
There is no iOS approved way of running a 5 minute (or any minute) timer in the background (unless your app is VOIP or music). What you CAN do is register your app as requiring location services in the background (edit the info.plist and add a key Required Background Modes and then add a value App registers for location updates. What this means is your locationManager:didUpdateToLocation:fromLocation: method and corresponding region monitoring/SLC methods will fire on location change, but Timers will not work at all.
The reason why is that timers require a run loop (a thread executing code) to be running and must piggy-back on that thread, but when the app is in the background even when executing code from the LocationManager, the run loop that executes the code almost always finishes before your timer would go off.
Hope this helps!
you cannot do this (on iOS).
(unless your app requests permissions that are meant for Navigation apps)
Hello #Aladdin Gallas,
I have developed a simple application that supports background location updates for iOS and Android in Xamarin.
The app pushes a new location every 2 seconds (you can change it to 5 minutes if you want to).
There is a feature I haven't been able to add; it is to keep the service up when the user closes the app (for iPhone). Other than that, as long as the app is open, even if the phone is locked, the service keeps running.
You can take a look at the application as a reference if it helps.
GitHub Repo

iphone: backgrounded app sync webservice

I know this question may be a little bit common and over asked but I cannot find any precise information... so :
Is it possible to have some kind of thread running when the app is in background so I can perform basic sync with my webservice ?
App is in background : I mean the user clicked the Home button, or switched to another app
basic sync : photo upload and download with AFNetworking. I know it has method to continue an HTTPRequest while app is in background, but this is not my point.
My goal would be to make some kind of sync manager, reading a list of photos to update created while the user was on the app, and perform those changes.
I know that the manager could be killed by the OS, but since my server uses atomic transfers it is not a problem. I just need a way to relaunch it... Push ?
I think apps like Google Latitude or Mail and those kind of apps uses what I am looking for but I cannot find any relevant details on it. And using iOS5 is not a problem but waiting for iOS6 would not be a solution.
Thank you for your replies !
PS : well I almost forgot. the app is designed for an enterprise program, so maybe rules are different ? I don't think there is any check for in-house deployment so it might lead to new possibilities...
Apple's Mail client has a background daemon which keeps it running but you can't have that with your own applications. Once an app enters a background state, it must halt it's operations. You can request for a little more time when backgrounded to finish off any transfers or writes to disk (see the Executing a Finite-Length Task in the Background section on Apple's Multitasking Guide)
Google Latitude has events generated based on location. This is a special type of backgrounding introduced by Apple for certain types of applications (see Implementing Long-Running Background Tasks section on Apple's Multitasking Guide) but this can't be used for HTTP syncing. It can only be used for audio, location, voip, newstand content, bluetooth and external hardware attachments.
Push doesn't seem like a solution because it only generates an alert. It doesn't trigger any action until the user triggers the opening of the notification.
You'll want to read Tech Note 2277 Networking and Multitasking.
Basically you have a couple of options:
If you can convince Apple that your app is a VoIP app then you can register a VoIP socket and the OS will resume your background app whenever there is activity on that socket.
Your main option though is to register a background task for any outstanding activity that you have to do when your app is put in the background. You typically get 10 minutes to finish up that work.
Mail is a special app with privileges you don't get.
Apps like Latitude typically register themselves for location updates, specifically to be woken up when there are major geo-position changes. Apps that record GPS tracks do similar things.
Found it !
Using Suhail Patel 's link on Apple's Multitasking Guide I added the voip tag to UIBackgroundModes in Info.plist and use setKeepAliveTimeout:handler: method of UIApplication to relaunch it if needed once the app is going to sleep.
I hope this will help a lot of you !
Of course this app won't be allowed to be on the App Store but for in house development this is in my opinion the best way to do so.
Thanks everyone for showing me the right direction !

Why does my iPhone App continue in the background?

I wrote my first iPhone App, and managed to get it into the App store. I later discovered a bug that happens on a real device but not on my emulator. I have committed a fix (changed plist to prevent app running in background), but I don't really understand why it happened.
My App allows users to record a sound-byte, however while they are recording they can use the iPhone home button to move the app to the background, and then it can keep recording forever if they don't restart the phone or the app does not crash.
My impression from everything I have read, is that this should not happen as you have to ask for background audio specifically if you want to do this, but now it appears to me that you have to ask specifically to disable it.
Could anyone explain this to me?
The iOS App lifecycle is described in Apple's iOS App Programming Guide.
The App is given the opportunity to save data and otherwise stop things that don't need to be running, before being suspended. You can request extra time doing this by using beginBackgroundTaskWithExpirationHandler:.
If you want your app to stop doing its "normal thing" when it is put into the background then you need to detect the App state transition and stop it yourself.