iOS-在 Google Drive Api 上使用上传图片(错误 "Assertion failure in: GTLServer...")

标签 ios ios6 google-drive-api

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

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)

这是我的相关代码:

- (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!"];
                      }
                }];
}

帮帮我!

最佳答案

GTMHTTPUploadFetcher 未链接,请将 -ObjC -all_load 添加到 Other Linker Flag 选项。

关于iOS-在 Google Drive Api 上使用上传图片(错误 "Assertion failure in: GTLServer..."),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17143038/

相关文章:

ios - UITableViewCell 已选择 subview 背景颜色已更改

ios - 启动react-native run-ios时Native-Module不能为Null

iphone - 使用 UICollectionViewFlowLayout 在 UICollectionView 的第一项上进行左填充

ios - 如何为 UINavigationBar setBackgroundImage 设置动画 : forBarMetrics:?

ios - Appirater 不要求审查

javascript - Google 应用脚本 UrlFetchApp 错误 "Access not granted or expired"

c# - Google Drive API v3 使用 JSON 而不是 P12(服务帐户)- 意外字符

ios - 使用 iOS SDK 从 Google Drive 下载文件

iphone - 如何仅使用 UITextField 制作 iOS 计算器

ios - Swift - 在所有设备的相同位置将 subview 添加到 UIImageView