Reputation: 970
I didn't know it was possible on iOS but lately I went to Japan and one of the free wifi apps wanted to install profile into my iPhone. When I confirmed installation it simply opened Safari with 127.0.0.1. It loaded some page and downloaded profile from there.
How do I host some page on iOS?
Upvotes: 1
Views: 402
Reputation: 341
Creating web server is nothing hard. It is lot of coding of course, but the principle is pretty easy.
There is lot of 3rd party libraries on the github (GCDWebService) just try to search for "ios http server"
To create it manually you need few steps:
1) With the help of CFSocketCreate
you open new socket with specific port (standard HTTP 80, or secured one 443 should be forbidden without root access rights) what going to listen on network interface on incomming requests.
2) You need to prepare some receiver what will be triggered as soon as some request income. You can use NSFileHandle
class and register NSFileHandleConnectionAcceptedNotification
in your notification center. And allow background mode with acceptConnectionInBackgroundAndNotify
method. But I recommend to read the manual first
NSFileHandle Apple documentation
3) Process the incoming request. The selector what you register is called and in NSNotification.userInfo
property is the incoming request, and you can generate some page here and open it in safari, or in your app or do whatever you want.
4) If you want received some POST data or streams, there is needs to register NSFileHandleDataAvailableNotification
what trigger selector as soon as some data to read are available.
Upvotes: 1