如何在iOS的默认“下载”文件夹中下载文件?

时间:2019-06-25 07:54:18

标签: ios swift download

在android中,您可以使用以下简单代码将文件下载到操作系统的默认“下载”文件夹中:

private void download(String url){
    if (ActivityCompat.checkSelfPermission(SectionManager.getInstance().getCurrentActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        PermissionManager.getInstance().requestPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE, PermissionManager.PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE);
    } else {
        DownloadManager.Request r = new DownloadManager.Request(Uri.parse(url));

        // This put the download in the same Download dir the browser uses            
        r.setDestinationInExternalFilesDir(SectionManager.getInstance().getCurrentActivity(), Environment.DIRECTORY_DOWNLOADS, url.substring(url.lastIndexOf('/')+1));

        // Notify user when download is completed
        // (Seems to be available since Honeycomb only)
        r.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);

        // Start download
        DownloadManager dm = (DownloadManager) SectionManager.getInstance().getCurrentActivity().getSystemService(DOWNLOAD_SERVICE);
        dm.enqueue(r);
    }
}

如何在iOS中完全相同?我需要下载一个文件,并给出了操作系统默认下载文件夹的URL。如何在iOS中做到这一点?抱歉,我的iOS技能很短

我还需要在IOS的通知部分中显示进度或类似内容。就像在Android中一样。

谢谢

0 个答案:

没有答案