简体   繁体   English

iOS-如何在后台运行应用程序?

[英]IOS - How to run an app in Background?

I'm developping an app, that one one his tasks, is to send messages in tcp to a server. 我正在开发一个应用程序,他的任务之一就是将tcp消息发送到服务器。 I want that the app continuos sending that tcp messages, even if the user quits the app. 我希望应用程序继续发送该tcp消息,即使用户退出了该应用程序也是如此。

I've that I could do that with: 我已经可以做到:

"In your Info.plist set LSBackgroundOnly to 1." “在您的Info.plist中,将LSBackgroundOnly设置为1。”

But it don't work (I just tested on the simulator). 但这不起作用(我刚刚在模拟器上进行了测试)。

Thanks a lot for the help! 非常感谢您的帮助!

I'll just put Holex's comment into answer form to take care of this question. 我将霍尔克斯的评论放入答案表以解决这个问题。 As he states, there are only 3 types of services allowed to run in the background of an application, location services, audio, and VoIP. 正如他所说,只有三种类型的服务允许在应用程序的后台运行:定位服务,音频和VoIP。 A great read on what you can and cant do is the following http://developer.apple.com/library/ios/#DOCUMENTATION/iPhone/Conceptual/iPhoneOSProgrammingGuide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html from Apple. 有关您可以做什么和不能做什么的好书,请访问以下来自Apple的http://developer.apple.com/library/ios/#DOCUMENTATION/iPhone/Conceptual/iPhoneOSProgrammingGuide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html Fairly detailed article of the structure of what happens when an application loses focus. 有关应用程序失去焦点时会发生什么的结构的相当详细的文章。

Alternatively however, if you don't plan on releasing through the app store, it is possible to fake a VoIP application and send/receive messages in the background. 但是,或者,如果您不打算通过应用程序商店发布,则可以伪造VoIP应用程序并在后台发送/接收消息。 This is not a legitimate solution however, and really should be used for nothing other than if you need something quick, and extremely dirty. 但是,这不是一个合法的解决方案,除非您需要快速且极其肮脏的东西,否则实际上不应将其用于其他任何用途。

iOS Voip Socket will not run in background That question, and any related ones are good places to start. iOS Voip Socket不会在后台运行该问题,任何相关问题都是一个很好的起点。

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

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