简体   繁体   English

是否可以在iOS上运行后台应用程序

[英]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. 这是一个奇怪的问题,我需要创建一个在iOS设备上在后台运行的iOS应用程序,但在设备的主屏幕上无法显示。 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 Backgrounding

There are several methods to get permanent background execution: 有几种方法可以获得永久的后台执行:

a) Silent audio which is mentioned by JRG-Developer a)JRG-Developer提到的静音

b) Usage of beginBackgroundTaskWithExpirationHandler + turning location manager on/off (it will reset remaining time to 600 seconds) b)使用beginBackgroundTaskWithExpirationHandler +打开/关闭位置管理器(它会将剩余时间重置为600秒)

Making app invisible 让app隐身

You can use SBAppTags in Info.plist (take a look at this: How to remove app icon programatically from jail broken iPhone app? ) 你可以在Info.plist中使用SBAppTags(看看这个: 如何从jail破解的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: 我不知道你如何解决not be visible on the home screen标准,但也被允许在后台运行不断,特别是某些服务:

  • Background Audio (even silent audio) 背景音频(甚至是无声音频)

While this is indeed very hacky, short of jailbreaking the devices, this may be your best bet. 虽然这确实非常hacky,但没有越狱设备,这可能是你最好的选择。

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 . 虽然通过审核流程不太可能/非常困难,但由于某种原因您确实需要(尝试)将此应用程序发布到App Store,甚至可以在App Store上使用某些应用程序来利用此黑客攻击,例如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 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? 另一个开箱即用的想法,为什么不使用Android设备 ,哪些支持多任务?

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. 越狱的iPhone本质上是一台Mac,你可以使用所有的Mac UNIX编程技巧 - 产生一个守护进程(你甚至可以让launchd这样做),或者什么。 You can set up enteprise-wise Cydia source. 你可以设置enteprise-wise Cydia源码。 Refer to saurik's website for a walkthrough and set up an experimental server using Ubuntu (which used apt too) 请参考saurik的网站进行演练并使用Ubuntu设置实验服务器(也使用了apt)

  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) 让它每天连接一次Web服务以注册设备ID(所以你知道用户没有删除应用程序)

  • 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. 如果你认为这是一个糟糕的想法,那就是,但它是你现在最好的iOS版本。

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. 编辑:您可以每天发送通知 - 例如在AM中 - 以确保用户打开应用程序(如果它没有运行)。

From my experince, this kind of behaviour cannot be achieved on iOS. 从我的经验来看,这种行为无法在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. 在那之后,它进入了hybernate状态。 It stops working. 它停止工作。 So the behaviour you said can not be achieved without abusing iOS workflow. 因此,如果不滥用iOS工作流程,就无法实现您所说的行为。 Thats why some call iOS's multitasking as not true multitasking. 这就是为什么有些人称iOS的多任务处理不是真正的多任务处理。 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. 在主屏幕上无法看到app的第二个也是不可能的。 It has to be on springboard to run. 它必须在跳板上运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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