2017-09-21 5 views
0

J'utilise l'API Google Drive. Lorsque j'utilise la démo pour obtenir la liste des fichiers, je pense que cette application fonctionne multi-thread. Maintenant, je veux obtenir la liste des fichiers lorsque la méthode réussit.Objective-C utilisant le bloc lors de l'obtention du fichier de liste à l'aide de l'API Google Driver

- (void)fetchFiles { 
    self.output.text = @"Getting files..."; 
    GTLQueryDrive *query = [GTLQueryDrive queryForFilesList]; 
    //query.pageSize = 10; /* Total number of files to get at once But useful only when there are more than hundreds of file to get once.*/ 
    query.fields = @"nextPageToken, files(id, name)"; 
    [self.service executeQuery:query delegate:self didFinishSelector:@selector(displayResultWithTicket:finishedWithObject:error:)]; 
} 
lien

: https://developers.google.com/drive/ios/quickstart

Répondre

0

Votre peut essayer.

@property (nonatomic, copy) void(^blockHandler)(id data); 


// get list file 
- (void)listFiles:(NSString *)fileId complete:(void(^)(id data))completion { 
self.blockHandler = completion; 

GTLRDriveQuery_FilesList *query = [GTLRDriveQuery_FilesList query]; 
query.fields = @"nextPageToken, files(id, name, thumbnailLink, webViewLink)"; 
query.pageSize = 1000; 
query.q = [NSString stringWithFormat:@"'%@' In parents and trashed=false",fileId]; 

[self.service executeQuery:query 
        delegate:self 
     didFinishSelector:@selector(displayResultWithTicket:finishedWithObject:error:)]; 
} 

- (void)displayResultWithTicket:(GTLRServiceTicket *)ticket 
     finishedWithObject:(GTLRDrive_FileList *)result 
         error:(NSError *)error { 
if (error == nil) { 
    NSMutableString *output = [[NSMutableString alloc] init]; 
    if (result.files.count > 0) { 
     [output appendString:@"Files:\n"]; 
     for (GTLRDrive_File *file in result.files) { 
      itemGG *temp = [[itemGG alloc] initWithName:file.name linkThumb:file.thumbnailLink fileID:file.identifier]; 
      [self.lstItem addObject:temp]; 
      [output appendFormat:@"%@ (%@)\n", file.name, file.identifier]; 
     } 
    } else { 
     [output appendString:@"No files found."]; 
    } 
    NSLog(@"%@", output); 
} else { 
    NSLog(@"Error getting presentation data: %@\n", error.localizedDescription); 
} 

if (self.blockHandler) { 
    self.blockHandler([[NSArray alloc] initWithArray:self.lstItem]); 
} 
} 


__weak typeof(self) w = self; 
[self.cloud listFiles:@"root" complete:^(id data) { 
    w.tableData = data; 
    [w.myCollection reloadData]; 
}]; 
+0

il travaille avec moi. Merci –

+0

Pas de problème ....... –