美文网首页
NSURLSession 接口翻译 (二)

NSURLSession 接口翻译 (二)

作者: 三三哥 | 来源:发表于2017-10-19 15:57 被阅读0次

    @interface NSURLSession (NSURLSessionAsynchronousConvenience)

    - (NSURLSessionDataTask *)dataTaskWithRequest:(NSURLRequest *)request completionHandler:(void (^)(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error))completionHandler;

    // block 形式返回数据,区别于代理!

    - (NSURLSessionUploadTask *)uploadTaskWithRequest:(NSURLRequest *)request fromFile:(NSURL *)fileURL completionHandler:(void (^)(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error))completionHandler;//上传方法,block 区别于代理

    - (NSURLSessionUploadTask *)uploadTaskWithRequest:(NSURLRequest *)request fromData:(nullable NSData *)bodyData completionHandler:(void (^)(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error))completionHandler;//上传 block 区别于代理

    - (NSURLSessionDownloadTask *)downloadTaskWithRequest:(NSURLRequest *)request completionHandler:(void (^)(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error))completionHandler;

    - (NSURLSessionDownloadTask *)downloadTaskWithURL:(NSURL *)url completionHandler:(void (^)(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error))completionHandler;

    - (NSURLSessionDownloadTask *)downloadTaskWithResumeData:(NSData *)resumeData completionHandler:(void (^)(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error))completionHandler;

    上面三个都是下载方法,下载完成之后在block 里面一定要把文件转移,因为文件会在出了block 之后被立即删除,文件放在tmp 临时文件不会被保存的!

    相关文章

      网友评论

          本文标题:NSURLSession 接口翻译 (二)

          本文链接:https://www.haomeiwen.com/subject/nueeuxtx.html