相关疑难解决方法(0)

下载PDF并保存到iPhone中的“文件”,而不是应用程序数据,Swift

我尝试使用以下代码下载pdf文件。它存储在应用程序数据中。但是我需要在iPhone的“文件”文件夹中显示下载的pdf 。

    // Create destination URL
    let documentsUrl:URL =  FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first as URL!
    let destinationFileUrl = documentsUrl.appendingPathComponent("downloadedFile.jpg")

    //Create URL to the source file you want to download
    let fileURL = URL(string: "http://swift-lang.org/guides/tutorial.pdf")

    let sessionConfig = URLSessionConfiguration.default
    let session = URLSession(configuration: sessionConfig)

    let request = URLRequest(url:fileURL!)

    let task = session.downloadTask(with: request) { (tempLocalUrl, response, error) in
        if let tempLocalUrl = tempLocalUrl, error == nil {
            // Success
            if let statusCode = (response as? HTTPURLResponse)?.statusCode {
                print("Successfully downloaded. …
Run Code Online (Sandbox Code Playgroud)

pdf file download ios swift

1
推荐指数
1
解决办法
4351
查看次数

标签 统计

download ×1

file ×1

ios ×1

pdf ×1

swift ×1