我正在使用objective-c框SDK使用专用方法管理文件
[[BoxSDK sharedSDK].filesManager downloadFileWithID:fileID
outputStream:outputStream
requestBuilder:nil
success:successBlock
failure:failureBlock
progress:progressBlock];
我需要能够取消下载任务,但我无法找到办法! 我还需要能够取消上传任务,但我想这样做的方式也是一样的......
有人设法实现这一目标吗?
答案 0 :(得分:2)
filesManager返回BoxAPIDataOperation。 最终BoxAPIDataOperation继承自NSOperation和Box基类,因为它是BoxAPIOperation。 要取消BoxAPIOperation,您只需向其发送消息取消。
事实上,BoxSDK中的所有资源管理器都返回从BoxAPIOperation继承的类。 您可以在BoxAPIOperation.m中找到(void)取消。
所以在你的情况下,你想要这样的东西
// property to store pointer to currently active download operation.
// it is weak, because you don't want to retain it. after download is completed, cancelled or failed
@property (nonatomic, readwrite, weak) BoxAPIDataOperation *downloadOperation;
....
self.downloadOperation = [[BoxSDK sharedSDK].filesManager downloadFileWithID:fileID
outputStream:outputStream
requestBuilder:nil
success:successBlock
failure:failureBlock
progress:progressBlock];
...
- (void)dealloc
{
[self.downloadOperation cancel];
}
// only if want to keep self in object and want to just cancel operation
- (void)userPressedCancelButton:(id)sender
{
[self.downloadOperation cancel];
}