Reputation: 19202
I want to continue to place file for an ios app in the same subdirectory beneath root of the user's drive.
I can create a new folder, create files within that new folder, but I don't want to be responsible for persisting the id of the folder I initially create into eternity. There has to be a way to rediscover the same directory and continue to place within that. The API doesn't seem to allow for it however. If I get a query that returns an array of GTLDriveChildReference
's there doesn't seem to be a title field with which to compare against the title of the directory I want to place my files in.
[GTLQueryDrive *query = [GTLQueryDrive queryForChildrenListWithFolderId:@"root"];
query.q = @"mimeType='application/vnd.google-apps.folder' and 'root' in parents and trashed=false";
[self.driveService executeQuery:query completionHandler::^(GTLServiceTicket *ticket,
GTLDriveChildList *children,
NSError *error) {
if (nil == error) {
for (GTLDriveChildReference *child in children) {
NSLog(@"File Id: %@", child.identifier);
}
} else {
NSLog(@"An error occurred: %@", error);
}
}];
Upvotes: 0
Views: 535
Reputation: 5554
Here's how I did it for a recent project, where I needed a folder called 'new'
func getFolderNewID()
{
// return the ID of the 'new' folder
// create it if it's not there
let query = GTLQueryDrive.queryForFilesList()
query.q = "'root' IN parents and title = 'new' and trashed = false"
googleDrive.service.executeQuery(
query,
delegate: self,
didFinishSelector: "returnedFolderForNew:finishedWithObject:error:")
}
func returnedFolderForNew(ticket : GTLServiceTicket, finishedWithObject response : GTLDriveFileList, error : NSError?)
{
if let _ = error
{
return
}
if response.items() == nil
{
// nothing returned - go create a folder
createFolderNew()
return
}
for fileItem in response.items()
{
googleDrive.folderNew = fileItem.identifier!!
}
}
Once you have that fileItem.identifier, you can use that in query, to check for identifier in parents
Upvotes: 1
Reputation: 2998
Google Drive API client for iOS should still be able to filter out queries because of Drive's query language you can specify the mimeType to be folder and query using its name.
Upvotes: 0