2014-09-20 48 views
0

執行以下操作將本地文件上傳到Google雲端硬盤會導致崩潰。爲什麼設置Google Drive文件的modifiedDate會導致iOS Drive api崩潰?

GTLDriveFile *gFile = [GTLDriveFile object]; 
gFile.title = "MyFileName.txt"; 

// Other file setup 

NSDate *myLocalDate = [self fileDate:myPath]; 
gFile.modifiedDate = [GTLDateTime dateTimeWithDate:myLocalDate timeZone:gmtZone]; 

// Other GTLQueryDrive and GTLUploadParameters calls 

query.setModifiedDate = YES; 
[service executeQuery:query completionHandler: (etc) 

fileDate:path方法返回正在上傳的本地文件的fileModificationDate屬性。崩潰消息是:

錯誤域= com.google.GTLJSONRPCErrorDomain代碼= 400「該操作無法完成。(無效的值爲:格式無效:」2014-09-14T13:21:58 + 00: 00「格式不正確

回答

1

我最近發現如何正確設置Google雲端硬盤文件的modifiedDate,併發布在stackoverflow問題14193307中。然後我遇到了上述問題,發現崩潰可能是Google雲端硬盤中的一個錯誤。SDK我的成功解決辦法是另一條線添加到我的FILEDATE:路徑的方法如下:

- (NSDate *)fileDate:(NSString *)path { 
    NSDictionary *attributes = [fMgr attributesOfItemAtPath:path error:nil]; 
    long long t = [attributes.fileModificationDate timeIntervalSince1970]; 
    return [NSDate dateWithTimeIntervalSince1970:t+.1]; 
} 

當谷歌驅動器SDK將其內部日期轉換爲JSON字符串,如果xxx = 0,它似乎會放棄.xxx毫秒部分。因此,上面那些不合格的代碼將.xxx強制爲.100,以便modifiedDate字符串變成例如。 {2014-09-20T05:58:37.100 + 00:00}這是有效的。