简体   繁体   中英

Is it possible to have a running background app on iOS

This is a strange one, I have a need to create an iOS app that runs in the background on an iOS device, but can not be visible on the Home screen of the device. The app may need to show up in Settings to configure a few options, but it mostly needs to run behind the scenes.

I do not need to publish this app on the app store , it is strictly an enterprise app for my company.

Does anyone know how this kind of behavior might be achieved? Configuration profiles? API's? etc?

Edit: Jailbreaking the device is not really an option for us. We have to keep the devices as they are.

Backgrounding

There are several methods to get permanent background execution:

a) Silent audio which is mentioned by JRG-Developer

b) Usage of beginBackgroundTaskWithExpirationHandler + turning location manager on/off (it will reset remaining time to 600 seconds)

Making app invisible

You can use SBAppTags in Info.plist (take a look at this: How to remove app icon programatically from jail broken iPhone app? )

It will make your icon not visible on Home screen.

I've no idea how you can tackle the not be visible on the home screen criteria, but there are certain services that are allowed to be run in the background continuously, notably:

  • Background Audio (even silent audio)

While this is indeed very hacky, short of jailbreaking the devices, this may be your best bet.

While it's unlikely / very difficult to get past the review process, in the event for some reason you do need to (attempt) to publish this app to the App Store, some apps are even available on the App Store which take advantage of this hack, such as PasteBot .

You should definitely read their write-up here about getting their app's Cut-and-Paste functionality to work while in the background:

http://tapbots.com/blog/pastebot/pastebot-music-in-background

Another out-of-the-box idea, why not use Android devices instead , which do support multitasking?

Two methods:

  1. Jailbreak. A jailbroken iPhone is essentially a Mac and you can use all Mac UNIX programming tricks - spawn a daemon (you can even ask launchd to do that), or something. You can set up enteprise-wise Cydia source. Refer to saurik's website for a walkthrough and set up an experimental server using Ubuntu (which used apt too)

  2. A non-jailbreak way may be possible, but it will depend on what your app is doing. You can try use enterprise-wise push notifications.

Given that this is impossible to do on non jailbroken phones, I'd suggest the following:

  • develop a directory app, or a phone list app, something that is specific to your company.

  • have it connect to a web service once a day to register the device ID (so you know the user has not deleted the app)

  • tell users they need to keep the app open at all times (and if a user's device does not register one day, send them an email asking them to launch the app).

Now you can send back whatever you want with the app. If they kill it, you'll know the next day when you have a script look at the logs.

If you think this is a terrible idea, it is, but its the best you are going to get on iOS right now.

EDIT: you could send a notification every day - say in the AM - to make sure the user opened the app if it wasn't running.

From my experince, this kind of behaviour cannot be achieved on iOS. When an app enters into background, it is active only for a small particular amount of time. After that, it goes into hybernate state. It stops working. So the behaviour you said can not be achieved without abusing iOS workflow. Thats why some call iOS's multitasking as not true multitasking. Only jailbreaking might help your case. That was for one case. The second one where the app cannot be seen on home screen is again, impossible. It has to be on springboard to run.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM