Reputation:
How can I make an app run at startup and not in the background. I need it in foreground for the whole time. Is that possible?
I have:
[UIApplication sharedApplication].idleTimerDisabled = YES;
Thats keeps an app always running in the foreground. But I don't know how make it run at iOS startup in foreground.
Upvotes: 3
Views: 46352
Reputation: 31339
The only way is Guided Access
Guided Access restricts your device to a single app and allows you to control which app features are available.
So, when you enable Guided Access, your app will run upon startup.
In order for it to work after a reboot (after a power failure or so), the passcode of the device needs to be disabled.
Upvotes: 5
Reputation: 75058
Remember that your app running all the time eats battery. Is that really the best thing for the user, or is there some way to get close to what you are trying to to via one of the many API's that support background processing on demand?
Look into the background data API introduced in IOS7. That's the easiest way to accomplish what you are likely trying to do.
Otherwise, look at one of the backgrounding modes and see if any of them might apply to your application.
OR look at the motion coprocessor data that the new iPhone 5s's gather without needing your app to be running...
Upvotes: 0
Reputation: 64644
If you plan on releasing this app onto the app store or on unmodified phones, it won't be possible because of the restrictions Apple places on apps for security reasons. However, if you just need the app for your own phone, you can look into jailbreaking which will give you more access to the system outside of the sandbox apple keeps most apps in.
Edit: Looking at this answer, there are ways to have your app run in the background at startup, but I think having it run in the foreground is still impossible.
Upvotes: 1