【发布时间】:2014-05-21 15:28:50
【问题描述】:
我正在尝试在 iOS 中制作谷歌驱动器文件管理应用程序。我被卡住了,因为我想使用任何关键字搜索所有文件,它应该是显示文件和文件夹。使用此代码获取所有文件和文件夹。但是如果您搜索某些内容,则仅搜索当前文件。你能建议我如何获取子文件和文件夹,因为它只显示单层而不是其他层。
-(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];
}];
}
【问题讨论】:
-
不清楚您的要求。你想要什么,你的代码现在在做什么?
-
此代码只是将文件和文件夹列出到 tableview 中。使用搜索显示控制器,它只搜索tableview中的当前文件和文件夹。我必须在文件中显示文件。例如文件夹 1 -> f1.txt、f2.txt。问题是当您搜索某些内容时,仅显示当前文件或文件夹。当您搜索 f1 时,它显示未找到。这意味着此代码适用于当前文件和文件夹,而不适用于子文件和子文件夹。那么,我应该怎么做才能在它的任何地方获取任何文件?
标签: xcode google-drive-api tableview uisearchdisplaycontroller