我实际上正在处理下载/上传文件并跟踪进度。它运作良好。但是,我只是想知道如果出现问题我会在这个委托中看到任何处理错误的方法。以下是NSURLSessionDownloadDelegate
的方法:
/*
* Messages related to the operation of a task that writes data to a
* file and notifies the delegate upon completion.
*/
@protocol NSURLSessionDownloadDelegate <NSURLSessionTaskDelegate>
/* Sent when a download task that has completed a download. The delegate should
* copy or move the file at the given location to a new location as it will be
* removed when the delegate message returns. URLSession:task:didCompleteWithError: will
* still be called.
*/
- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask
didFinishDownloadingToURL:(NSURL *)location;
@optional
/* Sent periodically to notify the delegate of download progress. */
- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask
didWriteData:(int64_t)bytesWritten
totalBytesWritten:(int64_t)totalBytesWritten
totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite;
/* Sent when a download has been resumed. If a download failed with an
* error, the -userInfo dictionary of the error will contain an
* NSURLSessionDownloadTaskResumeData key, whose value is the resume
* data.
*/
- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask
didResumeAtOffset:(int64_t)fileOffset
expectedTotalBytes:(int64_t)expectedTotalBytes;
@end
只是想知道如何丢弃错误信息,谢谢。
答案 0 :(得分:1)
让您的代表符合NSURLSessionTaskDelegate并执行:
- (void)URLSession:(NSURLSession *)session
task:(NSURLSessionTask *)task
didCompleteWithError:(NSError *)error
编辑进一步澄清,请参阅the doc for NSURLSessionDownloadDelegate,注意顶部附近的注意事项:
除了这些方法之外,一定要实现中的方法 要处理的NSURLSessionTaskDelegate和NSURLSessionDelegate协议 所有任务类型和会话级事件共有的事件, 分别
这个想法是url会话的委托可以符合这些协议中的任何一个。您正在查找的方法(指示错误的方法)比下载任务更通用,它可以在任何类型的会话任务中发生,因此它们将其置于更抽象的协议中。