问题标签 [nsinputstream]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
1461 浏览

ios - NSURLConnection 和绑定的流对(CFStreamCreateBoundPair 或 CFStreamCreateBoundPairCompat)在 iPhone 3G 上不起作用

我正在使用 SimpleURLConnections 示例使用绑定的流对来实现 multipart/form-data POST 请求。它在模拟器和 iPhone 3GS/iPhone 4 上运行良好。

当我在 iPhone 3G(运行 3.1.3)上尝试时,没有数据被发送到服务器。NSURLConnection 一直挂着,直到超时。经过一些测试后,我发现只有在每个连接多次写入生产者流时才会出现问题。每当我需要写不止一次时(即当我必须响应多个 NSStreamEventHasSpaceAvailable 事件时),事情就会停止工作。

这看起来像同样的问题:NSURLRequest with HTTPBody input stream: Stream 在打开之前发送事件,它确实提供了一种解决方法,但我还没有弄清楚我需要延迟什么才能解决问题。

0 投票
2 回答
595 浏览

nsinputstream - 关于 NSInputstream

Documents里面有一个文件,我想用这个方法加载到buffer中,但实际上读取总是-1,我的方法有问题吗?

0 投票
1 回答
431 浏览

iphone - istream和ostream的iphone功能

谁能告诉我以下代码中 istream 和 ostream 的功能以及我如何声明 istream 和 ostream,因为我从 net m 中挑选了代码,对代码了解不多

0 投票
1 回答
424 浏览

ios - 使用 EAAccessory 在 iOS 中处理配件状态

我正在开发一个 EAAccessory 项目,并且通常一切正常。附件是一个带有 5 个按钮的遥控器,与底座接口,底座向我的应用程序发送命令。这工作正常。但是,我被要求跟踪按钮状态,因此我应该能够识别按钮 1 和 2 是否保持在一起一秒钟。这似乎很复杂,我希望这可以在码头上处理。

通过一个字节的单个命令对外部附件状态进行建模时,有哪些好的编程实践?

0 投票
3 回答
3745 浏览

objective-c - 从文件读取内容时,NSInputStream 不会发生 NSStreamEventEndEncountered

我创建了一个 NSInputStream 来从文件(IOS)加载内容:

然后,添加事件处理程序:

我想捕捉事件:NSStreamEventEndEncountered,但没有发生。我只能捕获 NSStreamEventOpenCompleted 和 NSStreamEventHasBytesAvailable。

哪里不对了?谢谢你的帮助!

0 投票
1 回答
1122 浏览

nsinputstream - NSInputStream 读取:maxBytes 总是返回 0

我很困惑。我有一个开放的 NSInputStream 认为它有可用的字节。当我读取字节时,操作总是返回 0。我到处搜索,我的代码看起来像大多数其他人都在做同样的事情。这是一个如此低级的操作,我无法弄清楚它是如何出错的。我已经通过连接到许多不同的主机来尝试过这个。我也看过 Wireshark,我可以看到主机接收到我写的字节,但是 read:maxBytes 操作仍然总是返回 0???

0 投票
1 回答
1097 浏览

cocoa-touch - Cocoa 中的流类是否支持搜索?

我需要一个可以从内存流中读取和写入并支持查找的 Cocoa 类。在 C# 中,MemoryStream支持方法seek,在 Java 中,ByteArrayInputStream支持方法mark、、skipreset

在iOS开发中,等价的类和方法有哪些?

我的项目需要上述功能,如果默认情况下 iOS 框架不支持它,那么实现我自己的框架的最佳方法是什么?例如,编写我自己的流子类,继承自NSInputStream/NSOutputStream内部将包含自定义代码?

0 投票
0 回答
389 浏览

iphone - MpMoviePlayer 可以从 NSInputStream 获取它的数据吗

我有一个 iPad 应用程序,它具有来自另一台 iPad 的网络连接。在客户端 iPad 上,我希望能够从 NSInputStream (来自服务器 iPad)中获取数据,并在 MpMoviePlayer 从服务器 iPad 下载时播放它。

我知道我可以下载整个视频,将其保存到文件中,然后在媒体播放器中打开它,但我希望能够在下载完整文件之前开始播放。

我没有尝试将其中的一部分保存到文件中并播放它,然后在流中可用时添加到文件中,因为 a) 文件可能被锁定,并且 b) 电影播放器​​可能会打开文件并将其读入内部缓存,因此稍后添加到文件中不会(我不认为)播放新内容。如果没有人有任何绝妙的想法,我愿意在路上尝试,但我认为它成功的可能性非常低——我猜成功的几率是 10%。

如果 MpMoviePlayer 有一个 initWithData 方法,我会简单地给它一个 NSMutableData,并在数据流可用时添加到数据中,但我没有看到这样的方法。有人对我如何做到这一点有任何想法吗?

0 投票
0 回答
506 浏览

iphone - Streaming between two NSURLConnections, blocking NSInputStream read blocks all connections?

I'm trying to stream data between two iOS NSURLConenctions (one downloading, the other uploading), but can't seem to make it work.

  • I have two NSURLConnections running simultaneously.
  • One is downloading content from a url using a GET request.
  • The other is uploading the same content just received, to another url, in the request body of a PUT request.
  • In the upload connection I'm using setHTTPBodyStream to specify a custom NSInputStream whose read method returns data previously received from the other connection.
  • Both NSURLConnections are scheduled in the run loops of separate background threads, so that any (possibly blocking) delegate callbacks don't mess with each other (and neither with the main thread).

So I thought it would work like this:

  • The upload connection calls [read:maxLength] (which I have overridden) on the input stream.
  • Since there's no data available yet, the read call blocks.
  • On another thread, [connection:didReceiveData:] is called on the delegate of the download connection.
  • It puts the received data in a shared buffer, thus making it available for the input stream of the upload connection.
  • The upload stream's read call now isn't blocked anymore, it can return a chunk of data.

Unfortunately in practice, this does not work. After the upload stream's read method blocks, the download connection's delegate methods (eg. didReceiveData) don't get called anymore. (Note that if I disable the blocking on the upload side, then didReceiveData on the download side does get called all right.)

I suspect that this has to do something with the fact that the upload input stream's read method is called not on the thread where the connection and the stream objects were created, but on some other thread (apparently created by Cocoa). As if this was some shared thread used by both NSURLConnections, so once it's blocked, all other connections stop working as well. Or something like that.

Does anyone have an idea about what's really happening?

Also, is there a way to control on which thread the request body input stream's read method gets called?

0 投票
1 回答
432 浏览

iphone - NSInputStream 包装器通过指定的分隔符读取字符串

我正在将一个 java 客户端移植到 iphone,我一直想知道 NSInputStream 周围是否有一个包装器来从在指定分隔符处停止的流中读取字符串?我正在考虑类似 Javas Scanner 类(http://download.oracle.com/javase/6/docs/api/index.html?overview-summary.html)的东西。

我需要这个功能,因为我的 iphone 客户端正在从服务器接收消息,其中消息的结尾由字符 CR 和 LF 定义

我一直在搜索谷歌和stackoverflow,没有任何运气。只是要求确保我不会开始重新发明轮子可以这么说。

谢谢你的帮助!:=)