3

I have developed an iPhone application which will have some files (images, audio & video) in applications document directory (Note: File are in documents directory & not resources or main bundle).

I want to create a unique URL which will allow user to download these files(from apps document directory) from browser on other devices as Mac, smartphones, etc.

So may be in short make iOS application act as web server allowing to download application's files.

How to achieve this?

Arslan Ali
  • 17,418
  • 8
  • 58
  • 76
Sayali
  • 593
  • 3
  • 9
  • 22

1 Answers1

5

Try CocoaHTTPServer - you can use that to serve up a page with download links to files in the documents directory. (and to serve up the files themselves)

Ertebolle
  • 2,322
  • 2
  • 18
  • 22
  • I am able to use CocoaHTTPServer. I am able to connect through localhost on Simulator but on iPhone I am not able to connect. Please suggest. – Sayali Sep 01 '12 at 08:10
  • That might have to do with your iPhone's internet configuration - is it connected to the same WiFi router as your computer? – Ertebolle Sep 03 '12 at 00:02
  • Yes. Its connected to same wifi. And if this is the issue then atleast it should connect using iphone.local: on same device safari browser. Right? But its not connected on same device browser too. – Sayali Sep 03 '12 at 05:59
  • I am not able to connect on device. I have also posted new question for same [here](http://stackoverflow.com/questions/12245051/iphone-http-server-works-on-device-but-not-on-iphone-device) Please suggest – Sayali Sep 03 '12 at 09:20
  • Also is there any seyting on iPhone to make it act like webserver. Is there any ports I need to explicitly open for iPhone. Or may be some ports on wifi router? – Sayali Sep 03 '12 at 10:01
  • It wouldn't be able to connect with the app running in the background - server only works when it's in the foreground. So that explains why it can't connect from Safari on the device. The port would be specified at the end of the URL (after the :) - it's possible that port might be blocked for internal traffic on your router but it's pretty unlikely. Make sure you enter that port number on your computer's web browser, though. – Ertebolle Sep 03 '12 at 17:27
  • When i tried from other device with app in foreground it works. Thanks a lot. – Sayali Sep 04 '12 at 06:55
  • Now I have another doubt related to it. I have added code to download files listed. I have added "Content-Disposition = attachment" to make it downlodable. But on device it opens a file in browser itself. How can I make it save on Iphone device – Sayali Sep 04 '12 at 06:57
  • Making it save on an iPhone is impossible with Safari - it has nowhere to save files, all it can do is open them. However, if you write an app with a custom UIWebView, you can design it to check each link tapped on (in shouldStartLoadWithRequest:) to see if it's a file that should be downloaded, and if so, to download it (via an NSHTTPURLRequest) / save it to a file instead of opening it. – Ertebolle Sep 04 '12 at 16:04