我想从谷歌驱动器下载或导出文件。
- 用户在 UIWebView 上登录到谷歌驱动器
- 谷歌驱动器打开,用户选择任何特定文件,我得到一个特定选定文件的下载链接。
- 我在以下代码中使用该链接代替@“Google Drive file Url”:
-(BOOL)webView:(UIWebView *)awebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
if(navigationType == UIWebViewNavigationTypeLinkClicked)
{
GTMHTTPFetcher *fetcher =
[self.driveService.fetcherService fetcherWithURLString:@"Google Drive file Url"];
[fetcher beginFetchWithCompletionHandler:^(NSData *data, NSError *error)
{
if (error == nil)
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectoryPath = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectoryPath stringByAppendingPathComponent:@"dream.mp3"];
[data writeToFile:filePath atomically:YES];
}
else
{
NSLog(@"An error occurred: %@", error);
}
}];
}
}