0
  • Here the code:

    let url = NSURL(string: "http://a337.phobos.apple.com/us/r30/Music/d5/a8/6b/mzi.msfqeogi.aac.p.m4a") let downloadTask = self.downloadSession.downloadTaskWithURL(url!) downloadTask.resume() 

-> OK

-> it doesn't work; nothing happens

0

3 Answers 3

1

By default starting in iOS 9 all connections must be https. If the website for the second URL doesn't support https:// then the download would fail.

I suggest checking the error code you get back from the Download

Sign up to request clarification or add additional context in comments.

Comments

0

If you want to use url with HTTP connection, then in your info.plist file add the following App Transport Security Setting and in that add subsection Allow Arbitrary Loads and set the value to YES.

enter image description here

Comments

-2

Please add in Plist

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>NSAllowsArbitraryLoads</key> <true/> <key>NSExceptionDomains</key> <dict> <key>akamaihd.net</key> <dict> <key>NSExceptionRequiresForwardSecrecy</key> <false/> <key>NSIncludesSubdomains</key> <true/> </dict> <key>facebook.com</key> <dict> <key>NSExceptionAllowsInsecureHTTPLoads</key> <true/> <key>NSExceptionRequiresForwardSecrecy</key> <false/> <key>NSIncludesSubdomains</key> <true/> </dict> <key>fbcdn.net</key> <dict> <key>NSExceptionRequiresForwardSecrecy</key> <false/> <key>NSIncludesSubdomains</key> <true/> </dict> <key>graph.facebook.com</key> <dict> <key>NSExceptionAllowsInsecureHTTPLoads</key> <true/> <key>NSExceptionRequiresForwardSecrecy</key> <false/> <key>NSIncludesSubdomains</key> <true/> </dict> </dict> </dict> </plist> 

Then using Alamofire 4.0 Swift 3.0

Using below method, you can download any thing, ex. PDF

 // Mark:- Download File func DownloadFile(strFileUrl : String, strFileName : String, success:@escaping (_ strResultURL: String) -> Void , failure:@escaping (_ responseObject:AnyObject) -> Void) { let destination: DownloadRequest.DownloadFileDestination = { _, _ in let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0] let fileURL = documentsURL.appendingPathComponent("\(strFileName)") return (fileURL, [.removePreviousFile, .createIntermediateDirectories]) } Alamofire.download(strFileUrl, to: destination).response { response in if SVProgressHUD.isVisible() { SVProgressHUD.dismiss() } if response.error == nil { success("\(response.destinationURL!)") } else { failure(response.error as AnyObject) } }.downloadProgress { (progress) in print("Download Progress: \(progress.fractionCompleted)") SVProgressHUD.showProgress(Float(progress.fractionCompleted), status: AppAlertMsg.KDownloadingPDFs) } } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.