0

嘿伙计们,我正在从网络服务器上下载一个 yaml 文件。我NSInputStream的本地 yaml 文件效果很好(使用 file://filename.yaml url 方案)

这是相关的代码片段:

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

其中 yaml url 类似于 http://myip:8000/assets/test.yaml 在浏览器中打开只会导致文件下载...

有什么想法吗?

4

2 回答 2

1

我为时已晚,但我刚刚解决了这个确切的问题,所以这里是:

根据文档,

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

听起来很愚蠢,initWithURL 仅适用于本地文件。但是有一个简单的解决方法...

苹果的完整解释和代码示例可以在这里找到: https ://developer.apple.com/library/mac/documentation/cocoa/Conceptual/Streams/Articles/NetworkStreams.html#//apple_ref/doc/uid/20002277- BCIDFCDI

于 2014-01-07T10:46:00.477 回答
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.

于 2012-07-21T13:13:29.490 回答