gpt4 book ai didi

Swift Google Drive 下载文件

转载 作者:行者123 更新时间:2023-12-03 23:25:20 25 4
gpt4 key购买 nike

我不知道如何在 Swift 中下载 Google Drive 文件。我遵循了 Google Objective-C API 'GTL' with Swift 中修改后的快速入门这奏效了。我无法在下载文件时从 google drive API 翻译 objective-c 代码。我四处寻找,找不到任何东西。我怎样才能让它发挥作用?

最佳答案

您可以使用此函数在 Swift 中通过 Google Drive API 下载文件:

func downloadFile(file: GTLDriveFile){
let url = "https://www.googleapis.com/drive/v3/files/\(file.identifier!)?alt=media"

let fetcher = drive.fetcherService.fetcherWithURLString(url)

fetcher.beginFetchWithDelegate(
self,
didFinishSelector: #selector(ViewController.finishedFileDownload(_:finishedWithData:error:)))
}

(在这种情况下 driveGTLServiceDrive - 与 Documentation 相同)

那么就需要实现函数 finishedFileDownload下载完成后将调用它:
func finishedFileDownload(fetcher: GTMSessionFetcher, finishedWithData data: NSData, error: NSError?){
if let error = error {
//show an alert with the error message or something similar
return
}

//do something with data (save it...)
}

关于Swift Google Drive 下载文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25387893/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com