我正在iOS 8中开发应用程序,并且通过安装以下Pod集成了Google云端硬盘:

pod platform :ios, '8.0'

pod 'GoogleAPIClient/Drive', '~> 1.0.0'
pod 'GTMOAuth2', '~> 1.1.0'

当我放置代码以上传PDF文件时,出现以下错误:


  • 在类型'GTLDriveFile *'的对象上找不到属性'title'
  • 使用未声明的标识符'GTLDriveParentReference'。
  • 选择器'queryForFilesInsertWithObject:uploadParameters:'的未知类方法。


  • 这是我的代码:
    GTLDriveFile *driveFile = [GTLDriveFile object];
    
    driveFile.mimeType = @"application/pdf";
    driveFile.originalFilename = @"database.pdf";
    driveFile.name = @"database.pdf";
    driveFile.size = fileSizeNumber;
    NSString *parentId = @"root";
    driveFile.parents = @[parentId];
    
    NSData *fileContent = [[NSData alloc] initWithContentsOfFile:fileName];
    GTLUploadParameters *uploadParameters = [GTLUploadParameters uploadParametersWithData:fileContent MIMEType:@"application/pdf"];
    
    
    GTLDriveParentReference *parentRef = [GTLDriveParentReference object];
    parentRef.identifier = folderIdentifier; // identifier property of the folder
    driveFile.parents = @[ parentRef ];
    
    GTLQueryDrive *query = [GTLQueryDrive queryForFilesInsertWithObject:driveFile uploadParameters:uploadParameters];
    
    [self.service executeQuery:query
                  completionHandler:^(GTLServiceTicket *ticket,
                                      GTLDriveFile *updatedFile,
                                      NSError *error) {
                      if (error == nil) {
                          NSLog(@"\n\nfile uploaded into google drive\\<my_folder> foler");
                      } else {
                          NSLog(@"\n\nfile uplod failed google drive\\<my_folder> foler");
                      }
                  }];
    

    最佳答案

  • 使用driveFile.name代替driveFile.title
  • 没有GTLDriveParentReference类,因此删除这些行。
  • 使用queryForFilesCreateWithObject代替queryForFilesInsertWithObject
  • 10-08 01:11