问题
I want to embed a webserver in an iPhone app so as to download files from application's document directory. I am using iPhone Http Server.
Everything works fine on iPhone simulator. Even I am able to get files using http://: or localhost:.
But on device I am not able to connect. Safari says: "Cannot open page". Even http://iphone.local: doest not work on same device as app is installed.
Please suggest.
回答1:
Your app goes into background, doesn't it? I think you use Mac's Safari when you try your app in iOS Simulator. And when you try it on iPhone, your app is in background and iPhone's Safari is foreground.
If so, I believe the following helps you:
cocoaHTTPServer doesn't work in background. Try keep your app foreground and access it from other machine.
And, there is no way to maintain server functionality all the time... https://devforums.apple.com/message/706241
来源:https://stackoverflow.com/questions/12245051/iphone-http-server-works-on-simulator-but-not-on-iphone-device