"https://example/file.zip")! let task = URLSession.shared.downloadTask(with: url) { (location, response, error) in // Handle download completion } ``` 使用第三方库 Alamofire: `AF.request(url).downloadProgress { progress in ... }` SDWebImage: `SDWebImageManager.shared().loadImage(with: url, options: nil, progress: nil) { image, data, error, cacheType, finished, url in ... }` Android 使用 `DownloadManager` ```j多媒体a Uri downloadUri = Uri.parse("https://example/file.zip"); DownloadManager.Request request = new DownloadManager.Request(downloadUri); request.setDestinationInExternalFilesDir(context, Environment.DIRECTORY_DOWNLOADS, "file.zip"); DownloadManager downloadManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); long enqueue = downloadManager.enqueue(request); ``` 使用第三方库 Retrofit: `Retrofit.create(DownloadService.class).download(url).enqueue(new Callback() { ... });` Glide: `Glide.with(context).load(url).downloadOnly(new SimpleTarget() { ... });` 其他注意事项 确保已在清单中请求适当的权限(iOS:`NSAppTransportSecurity`;Android:`READ_EXTERNAL_STORAGE` 和 `WRITE_EXTERNAL_STORAGE`)。 考虑使用后台任务或服务在后台下载文件。 对于大型文件,请考虑分块下载以提高性能。