I am trying to make google drive file managing app in iOS. I am stuck because I want to search all files using any keyword and it should be display files and folder.Get all files and folder using this code.But if you search somthing, search only current file. Can you suggest me how to get subfiles and folder because it is display only single level not others.
-(void)getGDriveFilesAndFolders
{
GTLQueryDrive *query = [GTLQueryDrive queryForFilesList];
if ([self.strPath length] == 0)
{
query.q = @"'root' in parents";
}else{
NSString *queryString = [NSString stringWithFormat:@"'%@' in parents",self.strPath];
query.q=queryString;
}
[GoogleDriveViewController.driveService executeQuery:query completionHandler:^(GTLServiceTicket *ticket,GTLDriveFileList *files,NSError *error)
{
if (error == nil)
{
[marrFiles removeAllObjects];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"yyyy-MM-dd hh:mm:ss"];
for(int i = 0; i < [files items].count; i++)
{
GTLDriveFile *driveFile = (GTLDriveFile*)[files itemAtIndex:i];
if([driveFile.mimeType isEqualToString:@"application/vnd.google-apps.folder"])
{
if([driveFile.explicitlyTrashed intValue]!=1)
{
NSString *fileName = driveFile.title;
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
[dict setValue:fileName forKey:[NSString stringWithFormat:@"Folder"]];
[dict setValue:driveFile.identifier forKey:@"objectId"];
[marrFiles addObject:dict];
}
}
else{
if([driveFile.explicitlyTrashed intValue] != 1)
{
NSString *fileName = driveFile.title;
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
[dict setValue:fileName forKey:[NSString stringWithFormat:@"File"]];
long long int sizeData = [driveFile.fileSize intValue];
NSString *stringSize = [FileSizeClass stringSizeForFileWithBytes:[NSNumber numberWithLongLong:sizeData]];
GTLDateTime *modificationDate = (GTLDateTime*)driveFile.modifiedDate;
NSDate *date = [modificationDate date];
NSString *dateString = [dateFormatter stringFromDate:date];
dateString = [dateString createdTimeString];
NSString *stringInfo = [NSString stringWithFormat:@"%@ %@",stringSize,dateString];
[dict setValue:stringInfo forKey:[NSString stringWithFormat:@"Size"]];
[dict setValue:driveFile.identifier forKey:@"objectId"];
[dict setValue:driveFile.downloadUrl forKey:@"downloadUrl"];
[dict setValue:driveFile.fileSize forKey:@"FileSize"];
if(driveFile.webContentLink)
{
[dict setValue:driveFile.webContentLink forKey:@"webContentLink"];
}
[marrFiles addObject:dict];
}
}
}
[tblGoogleDrive reloadData];
} else {
UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:NSLocalizedString(@"Message",nil) message:[error localizedDescription] delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alertView show];
}
[MBProgressHUD hideAllHUDsForView:self.view animated:YES];
}];
}