简体   繁体   English

创建一个在后台作为Web服务器运行的iOS应用

[英]Create an iOS App that runs as Web Server in background

I want to make an iOS application (for iPad specifically), which behave like a web server. 我要制作一个iOS应用程序(专门用于iPad),其行为类似于Web服务器。 I saw the examples coming with COCOAHTTPSERVER, but i didn't understand something. 我看到了COCOAHTTPSERVER附带的示例,但我不明白。

Is it possible for my application, while being in background, to receive a request from another application running in the same device? 我的应用程序在后台时,是否有可能从同一设备上运行的另一个应用程序接收请求?

If it is possible how can i do this? 如果可能的话我该怎么办?

Otherwise, if it is impossible, what is the meaning of a web server application, that can't work in background? 否则,如果不可能,那么不能在后台运行的Web服务器应用程序是什么意思?

My exact problem is as follows: I need an iOS application that can receive a request from a javascript application, running on safari, in the same device. 我的确切问题如下:我需要一个iOS应用程序,该应用程序可以在同一设备上的safari中运行的javascript应用程序中接收请求。 Can i create an application behaving like a web server in background (because safari must be in foreground), or there is another way to implement this? 我可以在后台创建一个类似于Web服务器的应用程序(因为Safari必须在前台),还是有另一种方法可以实现此目的?

You can run a web server in the background on iOS but unfortunately only for a limited time (up to 10 minutes max) and the OS can stop it at any time. 可以在iOS上的后台运行Web服务器,但不幸的是,只能运行有限的时间(最多10分钟),操作系统可以随时将其停止。 See this tech note [1] for more info. 有关更多信息,请参见此技术说明[1]。

If that limitation is acceptable to you, you should use an already existing web server like GCDWebServer which handles background mode for you [2]. 如果您可以接受该限制,则应使用已经存在的Web服务器,例如GCDWebServer,它可以为您处理后台模式[2]。

[1] https://developer.apple.com/library/ios/technotes/tn2277/_index.html [1] https://developer.apple.com/library/ios/technotes/tn2277/_index.html

[2] https://github.com/swisspol/GCDWebServer#gcdwebserver--background-mode-for-ios-apps [2] https://github.com/swisspol/GCDWebServer#gcdwebserver--background-mode-for-ios-apps

This library may make your task much easier. 该库可以使您的任务轻松得多。

https://github.com/swisspol/GCDWebServer https://github.com/swisspol/GCDWebServer

No, iOS does not support web servers running in the background. 不可以,iOS不支持在后台运行的Web服务器。

The reason Apple does this is that a web server has to listen for inbound network requests. 苹果这样做的原因是Web服务器必须侦听入站网络请求。 Listening for inbound network requests requires that the radios be active all the time. 侦听入站网络请求要求无线电始终处于活动状态。 Active radios drain the battery. 有源无线电会耗尽电池电量。

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

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