本文介绍了iOS - 在Google Drive API上使用上传图片(错误“GTLServer ...中的声明失败”)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在iOS应用中使用Google云端硬盘。我尝试上传文件,出现以下错误:

  2013-06-17 14:38:57.964 GTL Demo [ *** GTLService uploadFetcherWithRequest:fetcherService:params:](),/Users/huylx612/demo2/google-api-objectivec-client-read-only/Source/Objects/GTLService.m中断言失败: 565 
2013-06-17 14:38:58.049 GTL Demo [6495:11303] ***终止应用程序,由于未捕获异常'NSInternalInconsistencyException',原因:'GTMHTTPUploadFetcher需要'
***首先抛出调用堆栈:
(0x1e01012 0x1307e7e 0x1e00e78 0xd9d6d0 0x3d0ba 0x3cb55 0x3de06 0x42a89 0x3642 0x2ee4 0x44ee3e 0xed7ed11 0xed772fd 0xedfa9f8 0x131b6b0 0xd47765 0x1d84f3f 0x1d8496f 0x1da7734 0x1da6f44 0x1da6e1b 0x21947e3 0x2194668 0x24bffc 0x26bd 0x25e5)
的libc ++ abi.dylib:终止叫做抛出例外
(lldb)

以下是我的相关代码:

   - (void)uploadPhoto:(UIImage *)image 
{
NSDateFormatter * dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@'Quickstart Uploaded File('EEEE MMMM d,YYYY h:mm a,zzz')];
GTLDriveFile *文件= [GTLDriveFile对象];
file.title = [dateFormat stringFromDate:[NSDate date]];
file.descriptionProperty = @从Google Drive iOS Quickstart上传;
file.mimeType = @image / png;

NSData * data = UIImagePNGRepresentation((UIImage *)image);

GTLUploadParameters * uploadParameters = [GTLUploadParameters uploadParametersWithData:data MIMEType:file.mimeType];
GTLQueryDrive * query = [GTLQueryDrive queryForFilesInsertWithObject:file $ b $ uploadParameters:uploadParameters];
UIAlertView * waitIndicator = [self showWaitIndicator:@上传到Google云端硬盘];

[self.driveService executeQuery:query
completionHandler:^(GTLServiceTicket * ticket,GTLDriveFile * insertedFile,NSError * error)
{
[waitIndicator dismissWithClickedButtonIndex:0 animated :是];
if(error == nil)
{
NSLog(@File ID:%@,insertedFile.identifier);
[self showAlert:@Google Drivemessage:@File saved!];
}
else
{
NSLog(@An error occurred:%@,error);
[self showAlert:@Google Drivemessage:@Sorry,an error occurred!];
}
}];
}

帮助我!

解决方案

GTMHTTPUploadFetcher 未链接,请添加 -ObjC -all_load 添加到其他链接标记选项。


I'm trying to use Google Drive in my iOS app. I try to upload a file, I get the following error:

2013-06-17 14:38:57.964 GTL Demo[6495:11303] *** Assertion failure in -[GTLService uploadFetcherWithRequest:fetcherService:params:](), /Users/huylx612/demo2/google-api-objectivec-client-read-only/Source/Objects/GTLService.m:565
2013-06-17 14:38:58.049 GTL Demo[6495:11303] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'GTMHTTPUploadFetcher needed'
*** First throw call stack:
(0x1e01012 0x1307e7e 0x1e00e78 0xd9d6d0 0x3d0ba 0x3cb55 0x3de06 0x42a89 0x3642 0x2ee4 0x44ee3e 0xed7ed11 0xed772fd 0xedfa9f8 0x131b6b0 0xd47765 0x1d84f3f 0x1d8496f 0x1da7734 0x1da6f44 0x1da6e1b 0x21947e3 0x2194668 0x24bffc 0x26bd 0x25e5)
libc++abi.dylib: terminate called throwing an exception
(lldb)

Here's my relevant code:

- (void)uploadPhoto:(UIImage*)image
{
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"'Quickstart Uploaded File ('EEEE MMMM d, YYYY h:mm a, zzz')"];
    GTLDriveFile *file = [GTLDriveFile object];
    file.title = [dateFormat stringFromDate:[NSDate date]];
    file.descriptionProperty = @"Uploaded from the Google Drive iOS Quickstart";
    file.mimeType = @"image/png";

    NSData *data = UIImagePNGRepresentation((UIImage *)image);

    GTLUploadParameters *uploadParameters = [GTLUploadParameters uploadParametersWithData:data MIMEType:file.mimeType];
    GTLQueryDrive *query = [GTLQueryDrive queryForFilesInsertWithObject:file
                                                       uploadParameters:uploadParameters];
    UIAlertView *waitIndicator = [self showWaitIndicator:@"Uploading to Google Drive"];

    [self.driveService executeQuery:query
                       completionHandler:^(GTLServiceTicket *ticket,GTLDriveFile *insertedFile, NSError *error)
                {
                      [waitIndicator dismissWithClickedButtonIndex:0 animated:YES];
                      if (error == nil)
                      {
                          NSLog(@"File ID: %@", insertedFile.identifier);
                          [self showAlert:@"Google Drive" message:@"File saved!"];
                      }
                      else
                      {
                          NSLog(@"An error occurred: %@", error);
                          [self showAlert:@"Google Drive" message:@"Sorry, an error occurred!"];
                      }
                }];
}

Help me!

解决方案

GTMHTTPUploadFetcher is not linked, please add -ObjC -all_load to the Other Linker Flag options.

这篇关于iOS - 在Google Drive API上使用上传图片(错误“GTLServer ...中的声明失败”)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 08:47