2017-04-16 245 views
1

根據here發佈的文檔,我可以用GTMSessionFetcher下載和上傳。 而點點文檔進一步形成鏈接我有一個代碼授權下載表格谷歌驅動器:GTMSessionfetcher谷歌驅動器UPLOAD谷歌驅動器的目標C?

GTLRQuery *query = [GTLRDriveQuery_FilesGet queryForMediaWithFileId:fileID]; 
NSURLRequest *downloadRequest = [service requestForQuery:query]; 
GTMSessionFetcher *fetcher = 
    [service.fetcherService fetcherWithRequest:downloadRequest]; 

[fetcher beginFetchWithCompletionHandler:^(NSData *data, NSError *fetchError) { 
    if (fetchError == nil) { 
    // Download succeeded. 
    } 
}]; 

它工作正常!

我的問題是:如何使用GTMSessionFetcher上傳到iOS版的Google雲端硬盤?

回答

0

從嘗試Google Toolbox for Mac - Session Fetcher這個代碼:

@interface GTMSessionUploadFetcher : GTMSessionFetcher 

// Create an upload fetcher specifying either the request or the resume location URL, 
// then set an upload data source using one of these: 
// 
// setUploadFileURL: 
// setUploadDataLength:provider: 
// setUploadFileHandle: 
// setUploadData: 

+ (instancetype)uploadFetcherWithRequest:(NSURLRequest *)request 
          uploadMIMEType:(NSString *)uploadMIMEType 
           chunkSize:(int64_t)chunkSize 
          fetcherService:(GTM_NULLABLE GTMSessionFetcherService *)fetcherServiceOrNil; 

+ (instancetype)uploadFetcherWithLocation:(NSURL * GTM_NULLABLE_TYPE)uploadLocationURL 
          uploadMIMEType:(NSString *)uploadMIMEType 
           chunkSize:(int64_t)chunkSize 
          fetcherService:(GTM_NULLABLE GTMSessionFetcherService *)fetcherServiceOrNil; 

- (void)setUploadDataLength:(int64_t)fullLength 
        provider:(GTM_NULLABLE GTMSessionUploadFetcherDataProvider)block; 

GitHub的代碼指出GTMSessionFetcher很容易可可應用程序執行HTTP操作。取出器實現爲一個包裝上NSURLSession,所以其行爲是異步的,在iOS和Mac OS X使用操作系統設置

希望這有助於。