ios - 如何在 AFNetworking 3.0 中设置 outputStream
<p><p>我在旧的 AFNetworking 中有一个选项来设置 outputStream:</p>
<pre><code>AFHTTPRequestOperation* requestOperation = [ initWithRequest:request];
requestOperation.outputStream = ;
</code></pre>
<p>如何在 AFNetworking 3.0 中实现这一点?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>在 AFHTTPSessionManager 上设置 setDataTaskDidReceiveDataBlock 以将数据写入缓冲区。然后使用 NSOutputStream 将该缓冲区写入文件。</p>
<pre><code>NSString *baseURLString = @"https://www.whatever.com";
NSString *pathString = "lol/rofl/";
AFHTTPSessionManager *manager = [ initWithBaseURL:];
manager.responseSerializer = [ init];
manager.responseSerializer.acceptableContentTypes = ;
[manager setDataTaskDidReceiveDataBlock:^(NSURLSession * _Nonnull session, NSURLSessionDataTask * _Nonnull dataTask, NSData * _Nonnull data) {
length:data.length];
}];
</code></pre>
<p>然后引用此 Apple 指南使用 NSOutputStream 和下面的流委托(delegate)回调方法将数据写入文件:<a href="https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Streams/Articles/WritingOutputStreams.html" rel="noreferrer noopener nofollow">https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Streams/Articles/WritingOutputStreams.html</a> </p>
<pre><code> - (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode
</code></pre></p>
<p style="font-size: 20px;">关于ios - 如何在 AFNetworking 3.0 中设置 outputStream,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/40973536/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/40973536/
</a>
</p>
页:
[1]