博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
在iphone上创建小型服务器,并且让其处于后台的时候服务器仍然处于运行状态
阅读量:4115 次
发布时间:2019-05-25

本文共 1115 字,大约阅读时间需要 3 分钟。

转自:http://www.mokten.com/2011/12/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  and a sleep timer based on by Marco Peluso.

 

Key Points

  1. Running a web server from an iPhone App is possible but will not respond when in the suspended or terminated state
  2. Stop the iPhone App going to the suspended state, when exiting, by playing an empty audio file
    1. Playing an audio file does not work in the iOS Simulator v5.0. So you need to test this on a device.
    2. Background executiion is only available in iOS 4 and later
    3. Reference: 

 

Overview

  1. MTAudioPlayer.m: plays an empty audio file that loops forever
    1. Based on old version of  by Marco Peluso
    2. Needed to be modified because the the periodic thread scheduling was not working in iOS 5
  2. iPhoneHTTPServer-Info.plist
  3. 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: 

Run the sample: /Samples/iPhoneHTTPServer

转载地址:http://pewpi.baihongyu.com/

你可能感兴趣的文章
链表练习
查看>>
加密与解密;解压缩
查看>>
插入排序和快速排序
查看>>
类与继承
查看>>
给定两个整形变量的值将两个值的内容进行交换
查看>>
求10 个整数中最大值。
查看>>
求两个数的最大公约数
查看>>
总结c语言的操作符
查看>>
练习3
查看>>
求出0〜999之间的所有“水仙花数”并输出。
查看>>
编程求Sn=a+aa+aaa+aaaa+aaaaa的前5项之和(a是一个数字);编程验证花括号成对出现。
查看>>
输出菱形
查看>>
函数编程的练习
查看>>
创建一个数组, 实现函数init()初始化数组、 实现reverse()函数完成数组元素的逆置,实现empty()清空数组。要求:自己设计函数的参数,返回值。
查看>>
写一个函数返回参数二进制中 1 的个数
查看>>
1.输出一个整数的每一位。2. 编程实现: 两个int(32位)整数m和n的二进制表达中,有多少个位(bit)不同?
查看>>
获取一个数二进制序列中所有的偶数位和奇数位,分别输出二进制序列。
查看>>
小游戏——猜数字
查看>>
在整型有序数组中查找想要的数字,找到了返回下标,找不到返回-1.(折半查找)
查看>>
编写一个程序,可以一直接收键盘字符,如果是小写字符就输出对应的大写字符,如果接收的是大写字符,就输出对应的小写字符,如果是数字不输出。
查看>>