I want to download or export file from google drive.
- User logged in to google drive on UIWebView
- Google Drive open, User select any particular file, I got one download link of particular selected file.
- 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);
}
}];
}
}