J'ai une vue d'évolution en alerte lors du téléchargement avec alamofire, mais le problème est que lorsque je veux télécharger la vue d'avancement en alerte commencera à être complète mais clignotante et l'autre problème est que l'écran derrière commencera à se fondre noir Je pense à chaque seconde une nouvelle alerte avec vue de progression montrera et à la fin il y a beaucoup d'alertes comment puis-je les éviter?Pourquoi les téléchargements alamofire progressent dans l'alerte clignotera et l'écran derrière deviendra noir?
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)
}
et voici les codes pour la minuterie
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()
}
}
que vous voyez dans mes codes je une autre variable qui contrôle la finition de téléchargement afin que le progrès est 1.0 Je veux rejeter alerte