0

Google ドライブからファイルをダウンロードまたはエクスポートしたい。

  1. UIWebView で Google ドライブにログインしたユーザー
  2. Google ドライブを開き、ユーザーが特定のファイルを選択すると、選択した特定のファイルのダウンロード リンクが 1 つ取得されました。
  3. 次のコードでは、@"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);
         }
     }];
}

}

4

0 に答える 0