欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

回头看看NSURLConnection

发布时间:2024/7/23 编程问答 48 豆豆
生活随笔 收集整理的这篇文章主要介绍了 回头看看NSURLConnection 小编觉得挺不错的,现在分享给大家,帮大家做个参考.
一、基础代理
1.使用场景网络错误提示,以及证书使用控制。
2.协议内容@protocol NSURLConnectionDelegate <NSObject>@optional- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error;- (BOOL)connectionShouldUseCredentialStorage:(NSURLConnection *)connection;是否使用证书- (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge;为指定的身份验证发送请求@end
二、数据代理
1.使用场景:用于监测数据的发送和接受,请求状态,缓存控制。
2.协议内容@protocol NSURLConnectionDataDelegate <NSURLConnectionDelegate>@optional- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response;- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response;- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data;- (NSInputStream *)connection:(NSURLConnection *)connection needNewBodyStream:(NSURLRequest *)request;- (void)connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)bytesWritten                                               totalBytesWritten:(NSInteger)totalBytesWritten                                       totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite;- (NSCachedURLResponse *)connection:(NSURLConnection *)connection willCacheResponse:(NSCachedURLResponse *)cachedResponse;- (void)connectionDidFinishLoading:(NSURLConnection *)connection;@end
三、下载代理:
1.使用场景:特意为Newsstand下载杂志数据而设立。  使用NKAssetDownload的downloadWithDelegate:(id<NSURLConnectionDownloadDelegate>)delegate方法时使用。
2.协议内容:@protocol NSURLConnectionDownloadDelegate <NSURLConnectionDelegate>@optional- (void)connection:(NSURLConnection *)connection didWriteData:(long long)bytesWritten totalBytesWritten:(long long)totalBytesWritten expectedTotalBytes:(long long) expectedTotalBytes;- (void)connectionDidResumeDownloading:(NSURLConnection *)connection totalBytesWritten:(long long)totalBytesWritten expectedTotalBytes:(long long) expectedTotalBytes;@required- (void)connectionDidFinishDownloading:(NSURLConnection *)connection destinationURL:(NSURL *) destinationURL;@end
四、方便发送同步请求的方法
+ (NSData *)sendSynchronousRequest:(NSURLRequest *)request returningResponse:(NSURLResponse **)response error:(NSError **)error;
五、方便发送异步请求的方法
+ (void)sendAsynchronousRequest:(NSURLRequest*) request                          queue:(NSOperationQueue*) queue              completionHandler:(void (^)(NSURLResponse* response, NSData* data, NSError* connectionError)) handler NS_AVAILABLE(10_7, 5_0);

总结

以上是生活随笔为你收集整理的回头看看NSURLConnection的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。