使 iOS 应用程序在启动时运行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20864999/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 22:55:43  来源:igfitidea点击:

Make iOS application run at startup

iosiphoneipadstartup

提问by Dmitriy Pushkarev

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.

这使应用程序始终在前台运行。但我不知道如何让它在前台的 iOS 启动时运行。

回答by Shamsudheen TK

The only way is Guided Access

唯一的方法是引导式访问

Guided Access limits your device to a single app and lets you control which app features are available.

引导式访问将您的设备限制为单个应用程序,并让您控制哪些应用程序功能可用。

So when the Guided Access is ON, your app run at 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.

为了让它在重新启动后(在断电后)工作,需要禁用设备的密码。

回答by Connor

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.

如果您计划将此应用程序发布到应用程序商店或未经修改的手机上,这是不可能的,因为 Apple 出于安全原因对应用程序施加了限制。但是,如果您只需要为自己的手机安装该应用程序,则可以考虑越狱,这将使您能够更多地访问苹果将大多数应用程序保留在沙盒之外的系统。

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.

编辑:看看这个答案,有很多方法可以让你的应用程序在启动时在后台运行,但我认为让它在前台运行仍然是不可能的。

回答by Kendall Helmstetter Gelner

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?

请记住,您的应用程序一直运行会消耗电池电量。这对用户来说真的是最好的事情,还是有什么方法可以通过支持按需后台处理的众多 API 之一来接近您想要做的事情?

Look into the background data API introduced in IOS7. That's the easiest way to accomplish what you are likely trying to do.

查看IOS7中引入的后台数据API。这是完成您可能尝试做的事情的最简单方法。

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...

或者查看新 iPhone 5s 收集的运动协处理器数据,而无需运行您的应用程序...