0

Dynamically need to update. I'm able to download the certificate from a URL and save it to the document directory.

func downloadFile(url: URL, completion: @escaping (String?, Error?) -> Void) {
    let documentsUrl = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
    let destinationUrl = documentsUrl.appendingPathComponent(url.lastPathComponent)
    if FileManager().fileExists(atPath: destinationUrl)
    {
        print("File already exists [\(destinationUrl)]")
        completion(destinationUrl, nil)
    }
    if let dataFromURL = NSData(contentsOf: url)
    {
        if dataFromURL.write(to: URL(string: destinationUrl)!, atomically: true)
        {
            print("file saved [\(destinationUrl)]")
            completion(destinationUrl, nil)
        }
        else
        {
            print("error saving file")
            let error = NSError(domain:"Error saving file", code:1001, userInfo:nil)
            completion(destinationUrl, error)
        }
    }
    else
    {
        let error = NSError(domain:"Error downloading file", code:1002, userInfo:nil)
        completion(destinationUrl, error)
    }
}

My question is after download the file need to save into App Bundle (Bundle.main.resourcePath) directory.
or save it to the document folder and move it to the App Bundle directory?.

1 Answer 1

1

You can't move stuff to the Bundle directory. This is a read only directory. You have to read them from Documents and use code to create certificate pinning by reading the files manually (or using Alamofire)

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

1 Comment

I'm using Alamofire only, but Alamofire automatically take certificate app bundle only (Bundle.main.af.certificates) Is Alamofire provide any property to change the certificate directory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.