0

I want to download or export file from google drive.

  1. User logged in to google drive on UIWebView
  2. Google Drive open, User select any particular file, I got one download link of particular selected file.
  3. I used that link in place of @"Google Drive file Url" in following code:

-(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);
         }
     }];
}

}

Kiran Patel
  • 325
  • 1
  • 3
  • 8

0 Answers0