首页 > 解决方案 > 快速识别来自 weburl 的资源名称和扩展名

问题描述

在此处输入图像描述在 chrome 中粘贴下面的 url,chrome 将为您提供带有扩展名的确切文件名。

https://www.videvo.net/download_new.php?hash=f654a8d8307038ae523769b502f35ab5&test_new_server=1

就像 chrome 知道名称和扩展名一样,我想用 swift 做到这一点。

提前谢谢你。

标签: iosswift

解决方案


您可以downloadTask.response?.suggestedFilename从下面使用它func

 func URLSession(session: URLSession, downloadTask: URLSessionDownloadTask, didFinishDownloadingToURL location: NSURL) {
        print(downloadTask.response?.suggestedFilename as Any)
        print(downloadTask.response?.mimeType as Any)

    }

推荐阅读