使用UIWebView下载google驱动器文件

时间:2014-05-23 06:01:30

标签: ios uiwebview google-drive-api gtm-oauth2

我想从谷歌硬盘下载或导出文件。

  1. 用户在UIWebView上登录google云端硬盘
  2. 谷歌云端硬盘开放,用户选择任何特定文件,我有一个特定选定文件的下载链接。
  3. 我在以下代码中使用该链接代替@“Google Drive文件Url”:
  4. - (BOOL)webView:(UIWebView *)awebView shouldStartLoadWithRequest:(NSURLRequest *)请求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);
             }
         }];
    }
    

    }

0 个答案:

没有答案