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)
}
여기에 내가 다운로드 마무리를 제어하는 또 다른 변수가 너무 진행 내가 경고를 해제 할 1.0 때 타이머
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()
}
}
에 대한 코드입니다