转自:http://www.mokten.com/2011/12/run-a-web-server-from-an-iphone-app/
Run a Web Server from an iPhone App
Yoo-Jin Lee Wed, Dec 14, 2011
If you ever needed to run a simple web server from an iPhone App here is one way to do it.
This example uses a lightweight web server cocoahttpserver and a sleep timer based onMMPDeepSleepPreventer by Marco Peluso.
Key Points
- Running a web server from an iPhone App is possible but will not respond when in the suspended or terminated state
- Stop the iPhone App going to the suspended state, when exiting, by playing an empty audio file
- Playing an audio file does not work in the iOS Simulator v5.0. So you need to test this on a device.
- Background executiion is only available in iOS 4 and later
- Reference: iOS Developer Library
Overview
- MTAudioPlayer.m: plays an empty audio file that loops forever
- Based on old version of MMPDeepSleepPreventer by Marco Peluso
- Needed to be modified because the the periodic thread scheduling was not working in iOS 5
- iPhoneHTTPServer-Info.plist
- Add property: Required background modes: App plays audio
- iPhoneHTTPServerViewController.m: Opens up the localhost server URL and should show /Web/index.html
Full sample code: cocoahttpserver
Run the sample: /Samples/iPhoneHTTPServer
本文介绍了一种从iPhone应用程序中运行轻量级Web服务器的方法。该方案利用了cocoahttpserver并结合MMPDeepSleepPreventer防止应用进入休眠状态。为保持后台运行,应用需播放无声文件,并需在iOS4及以上版本中测试。
4万+

被折叠的 条评论
为什么被折叠?



