Instance Method


Asynchronously reads a number of bytes from the stream, and calls a handler upon completion.


- (void)readDataOfMinLength:(NSUInteger)minBytes maxLength:(NSUInteger)maxBytes timeout:(NSTimeInterval)timeout completionHandler:(void (^)(NSData *data, BOOL atEOF, NSError *error))completionHandler;



The minimum number of bytes to read.


The maximum number of bytes to read.


A timeout for reading bytes. If the read is not completed within the specified interval, the read is canceled and the completionHandler is called with an error. Pass 0 to prevent a read from timing out.


The completion handler to call when all bytes are read, or an error occurs. This handler is executed on the delegate queue.

This completion handler takes the following parameters:


The data read from the stream.


Whether or not the stream reached end-of-file (EOF), such that no more data can be read.


An error object that indicates why the read failed, or nil if the read was successful.

See Also

Reading and Writing Data

- writeData:timeout:completionHandler:

Asynchronously writes the specified data to the stream, and calls a handler upon completion.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software