как вы упомянули, вы можете получить данные из GDoc, что означает, что вы сделали с частью аутентификации.SO Для загрузки файла в Google Doc используйте следующий код.
NSString *errorMsg = nil;
// make a new entry for the file
NSString *mimeType = nil;
Class entryClass = nil;
NSString *extn = [path pathExtension];
[self getMIMEType:&mimeType andEntryClass:&entryClass forExtension:extn];
if (!mimeType)
{
// for other file types, see if we can get the type from the Mac OS
// and use a generic file document entry class
mimeType = [GDataUtilities MIMETypeForFileAtPath:path
defaultMIMEType:nil];
entryClass = [GDataEntryFileDoc class];
}
if (!mimeType)
{
errorMsg = [NSString stringWithFormat:@"need MIME type for file %@", path];
}
if (mimeType && entryClass)
{
GDataEntryDocBase *newEntry = [entryClass documentEntry];
NSString *title = [[NSFileManager defaultManager] displayNameAtPath:path];
[newEntry setTitleWithString:title];
NSFileHandle *uploadFileHandle = [NSFileHandle fileHandleForReadingAtPath:path];
if (!uploadFileHandle)
{
errorMsg = [NSString stringWithFormat:@"cannot read file %@", path];
}
if (uploadFileHandle)
{
[newEntry setUploadFileHandle:uploadFileHandle];
[newEntry setUploadData:[NSData dataWithContentsOfFile:path]];
[newEntry setUploadMIMEType:mimeType];
[newEntry setUploadSlug:[path lastPathComponent]];
NSURL *uploadURL = [GDataServiceGoogleDocs docsUploadURL];
GDataServiceGoogleDocs *service = [self docsService];
[service setAuthorizer:self.authentication];
GDataServiceTicket *ticket;
ticket = [service fetchEntryByInsertingEntry:newEntry
forFeedURL:uploadURL
delegate:self
didFinishSelector:@selector(uploadFileTicket:finishedWithEntry:error:)];
[self setUploadTicket:ticket];
}
}
if (errorMsg)
{
[self displayAlert:@"Upload Error"
format:@"%@", errorMsg];
NSLog(@"%@", errorMsg);
}
Метод для Mime Type.
- (void)getMIMEType:(NSString **)mimeType andEntryClass:(Class *)class forExtension:(NSString *)extension {
// Mac OS X's UTI database doesn't know MIME types for .doc and .xls
// so GDataEntryBase's MIMETypeForFileAtPath method isn't helpful here
struct MapEntry {
NSString *extension;
NSString *mimeType;
NSString *className;
};
static struct MapEntry sMap[] = {
{ @"csv", @"text/csv", @"GDataEntryStandardDoc" },
{ @"doc", @"application/msword", @"GDataEntryStandardDoc" },
{ @"docx", @"application/vnd.openxmlformats-officedocument.wordprocessingml.document", @"GDataEntryStandardDoc" },
{ @"ods", @"application/vnd.oasis.opendocument.spreadsheet", @"GDataEntrySpreadsheetDoc" },
{ @"odt", @"application/vnd.oasis.opendocument.text", @"GDataEntryStandardDoc" },
{ @"pps", @"application/vnd.ms-powerpoint", @"GDataEntryPresentationDoc" },
{ @"ppt", @"application/vnd.ms-powerpoint", @"GDataEntryPresentationDoc" },
{ @"rtf", @"application/rtf", @"GDataEntryStandardDoc" },
{ @"sxw", @"application/vnd.sun.xml.writer", @"GDataEntryStandardDoc" },
{ @"txt", @"text/plain", @"GDataEntryStandardDoc" },
{ @"xls", @"application/vnd.ms-excel", @"GDataEntrySpreadsheetDoc" },
{ @"xlsx", @"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", @"GDataEntrySpreadsheetDoc" },
{ @"jpg", @"image/jpeg", @"GDataEntryStandardDoc" },
{ @"jpeg", @"image/jpeg", @"GDataEntryStandardDoc" },
{ @"png", @"image/png", @"GDataEntryStandardDoc" },
{ @"bmp", @"image/bmp", @"GDataEntryStandardDoc" },
{ @"gif", @"image/gif", @"GDataEntryStandardDoc" },
{ @"html", @"text/html", @"GDataEntryStandardDoc" },
{ @"htm", @"text/html", @"GDataEntryStandardDoc" },
{ @"tsv", @"text/tab-separated-values", @"GDataEntryStandardDoc" },
{ @"tab", @"text/tab-separated-values", @"GDataEntryStandardDoc" },
{ @"pdf", @"application/pdf", @"GDataEntryPDFDoc" },
{ nil, nil, nil }
};
NSString *lowerExtn = [extension lowercaseString];
for (int idx = 0; sMap[idx].extension != nil; idx++) {
if ([lowerExtn isEqual:sMap[idx].extension]) {
*mimeType = sMap[idx].mimeType;
*class = NSClassFromString(sMap[idx].className);
return;
}
}
*mimeType = nil;
*class = nil;
return;
}
, если вы следуете примеру кода gDoc.Затем с помощью вышеуказанного кода вы сможете загрузить файл в Gdoc.Удачи.