0

Hey guys so I'm pulling down a yaml file from a web server. My NSInputStream works great with local yaml files (using file://filename.yaml url scheme)

Here's the relevant code snippet:

NSInputStream * stream = [[NSInputStream alloc] initWithURL:yamlURL];

Where yaml url is something like http:// myip:8000/assets/test.yaml Opening in a browser just results in file download...

Any thoughts?

Janak Nirmal
  • 22,706
  • 18
  • 63
  • 99
Msencenb
  • 5,675
  • 11
  • 52
  • 84
  • I'm having the same problem. `initWithURL` and `inputStreamWithURL` are both returning `nil`, even though I can successfully download the file in question by using `NSURLConnection` using the same URL. Any success getting `initWithURL` to work? – Rob Dec 05 '12 at 06:05
  • See my comment below... Basically I solved it by downloading into NSData prior to working with the file – Msencenb Dec 05 '12 at 06:13
  • 1
    Yes, I'm familiar with that. `NSData` not practical for big (hundreds of MB) files. Clearly, I can download to local file (I already have a downloader class that avoids loading the whole thing in a `NSData` at any given time), but even that is horribly inefficient (I have to wait for the big honking download to finish before I can start using it) when I want web-based streaming solution. I'm about to subclass NSInputStream to do what I need, but that seems silly ... `inputStreamWithURL` should just do the job. I want to see if I can get that to work before I roll my own. – Rob Dec 05 '12 at 06:34

2 Answers2

1

Im way too late for this, but i just solved this exact problem, so here goes:

As per the docs,

The NSStream class does not support connecting to a remote host on iOS.

As stupid as this sounds, initWithURL will only work for a local file. But theres an easy fix...

Full explanation and code sample from apple can be found here: https://developer.apple.com/library/mac/documentation/cocoa/Conceptual/Streams/Articles/NetworkStreams.html#//apple_ref/doc/uid/20002277-BCIDFCDI

katzenhut
  • 1,742
  • 18
  • 26
0

Is there anything you're doing with the *stream, After you initWithURL?

If you are taking the content from the InputStream inited with the local file, you would need to be creating a NSOutputStream to take the InputStream and redirect it to Safari. So I don't think just initWithURL: call with the url will tell you much, but the call to open the http:// url in safari will try to determine the content-type and try to output the file. But I don't think safari would be able to display the contents if it was a mulit-part mime yaml file.

Pareshkumar
  • 176
  • 6
  • So to workaroudn the many 'if's of nsinput stream as said by pareshkumar I actually am now downloading into an NSData from url (or local file), then initializing the input stream with this data. Much more stable and easy to use. – Msencenb Jul 22 '12 at 20:37