ios – 停止/取消在AWS S3上的上传

我使用AWSLocal内容上传方式上传文件.我需要从另一个屏幕上取消上传.

这是上传功能

private func uploadLocalContent(localContent: AWSLocalContent) {
    localContent.uploadWithPinOnCompletion(false,progressBlock: {[weak self](content: AWSLocalContent?,progress: nsprogress?) -> Void in
        guard let strongSelf = self else { return }
        dispatch_async(dispatch_get_main_queue()) {
            // Update the upload UI if it is a new upload and the table is not yet updated
            if(strongSelf.tableView.numberOfRowsInSection(0) == 0 || strongSelf.tableView.numberOfRowsInSection(0) < strongSelf.manager.uploadingContents.count) {
                strongSelf.updateUploadUI()
            } else {

                for uploadContent in strongSelf.manager.uploadingContents {
                    if uploadContent.key == content?.key {
                        let index = strongSelf.manager.uploadingContents.indexOf(uploadContent)!
                        let indexPath = NSIndexPath(forRow: index,inSection: 0)
                        strongSelf.tableView.reloadRowsAtIndexPaths([indexPath],withRowAnimation: .None)
                    }
                }
            }
        }
        },completionHandler: {[weak self](content: AWSContent?,error: NSError?) -> Void in
            guard let strongSelf = self else { return }
            strongSelf.updateUploadUI()
            if let error = error {
                print("Failed to upload an object. \(error)")
                strongSelf.showSimpleAlertWithTitle("Error",message: "Failed to upload an object.",cancelButtonTitle: "OK")
            } else {
                strongSelf.refreshContents()
            }
        })
    updateUploadUI()
}

解决方法

不幸的是,AWSLocalContent调用时无法取消上传,因为无法访问AWTask.

查看awss3transfermanager(http://docs.aws.amazon.com/AWSiOSSDK/latest/Classes/AWSS3TransferManager.html#//api/name/upload :),为每个操作创建一个AWTask,可以上传或下载,可以取消/暂停/恢复.此外,您可以从awss3transfermanager获取方便的方法,可以一次取消/暂停/恢复所有任务.

您必须创建上传AWTask,将其保留在可从其他屏幕访问的位置,然后您就可以取消它.

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...