1
我有戒备发展观与alamofire下载时,但问题是,当我想下载警报进度视图将开始完成,但闪烁,另一个问题是,后面的屏幕将开始成为褪色黑色我认为每秒都会显示一个带有进度视图的新警报,并且最后会有很多警报,我该如何避免它们?为什么alamofire下载警报的进度会闪烁,后面的屏幕开始变黑?
downloadTimer = Timer.scheduledTimer(timeInterval: 1 , target: self, selector: #selector(flashingDownload), userInfo: nil, repeats: true)
let destination = DownloadRequest.suggestedDownloadDestination()
Alamofire.download("http://example.com", to: destination).downloadProgress(queue: DispatchQueue.global(qos: .utility)) { (progress) in
print("Progress: \(progress.fractionCompleted)")
sixthLevelViewController.progressdownload = Float(progress.fractionCompleted)
if sixthLevelViewController.progressdownload == 1.0 {
self.downloadfinished = true
let alertController = UIAlertController(title: "finish download ", message: " download Completed! ", preferredStyle: UIAlertControllerStyle.alert)
let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.default)
{
(result : UIAlertAction) -> Void in
self.view.isUserInteractionEnabled = true
}
alertController.addAction(okAction)
self.present(alertController, animated: true, completion: nil)
alertController.view.tintColor = UIColor.green
alertController.view.backgroundColor = UIColor.green
alertController.view.layer.cornerRadius = 0.1 * alertController.view.bounds.size.width
}
} .validate().responseData { (response) in
print(response.destinationURL!.lastPathComponent)
}
,这里是定时器
func flashingDownload() {
while (topViewController.presentedViewController != nil){
topViewController = topViewController.presentedViewController!
}
DispatchQueue.main.async {
let alert = UIAlertController(title: "downloading", message: "pls wait", preferredStyle: .alert)
let progressBar = UIProgressView(progressViewStyle: .default)
progressBar.setProgress(sixthLevelViewController.progressdownload, animated: true)
progressBar.frame = CGRect(x: 10, y: 70, width: 250, height: 0)
alert.view.addSubview(progressBar)
self.topViewController.present(alert, animated: false, completion: nil)
if sixthLevelViewController.progressdownload == 1.0 {
print("finished download !")
self.topViewController.dismiss(animated: false , completion: nil)
self.downloadTimer.invalidate()
}
}
代码正如你在我的代码看,我认为控制下载完成另一个变量,所以当进度为1.0我想关闭提醒