Reputation: 11
I am writing code in swift.I was trying to integrate google drive using the below link https://developers.google.com/drive/ios/quickstart. i downloaded the google client library using link https://github.com/google/google-api-objectivec-client.git which is mentioned in step 2 of google's developer guide. i am able to run the example code here successfully. but i have to upload file to google drive. so i am using queryForFilesInsertWithObject method. but i am getting error GTLQueryDrive' has no member 'queryForFilesInsertWithObject'.my sample code is below:
func uploadPhoto(image: UIImage) {
print("uploading Photo")
let dateFormat = NSDateFormatter()
dateFormat.dateFormat = "'Quickstart Uploaded File ('EEEE MMMM d, YYYY h:mm a, zzz')"
let file = GTLDriveFile() as GTLDriveFile
//file.title = dateFormat.stringFromDate(NSDate())
file.descriptionProperty = "Uploaded from Google Drive IOS"
file.mimeType = "image/png"
let data = UIImagePNGRepresentation(image)
let uploadParameters = GTLUploadParameters(data: data!, MIMEType: file.mimeType)
let query = GTLQueryDrive.queryForFilesInsertWithObject(file, uploadParameters: uploadParameters) as! GTLQueryDrive
//let waitIndicator = self.showWaitIndicator("Uploading To Google Drive")
self.service.executeQuery(query, completionHandler: { (ticket, insertedFile , error) -> Void in
let myFile = insertedFile as? GTLDriveFile
// waitIndicator.dismissWithClickedButtonIndex(0, animated: true)
if error == nil {
print("File ID \(myFile?.identifier)")
self.showAlert("Google Drive", message: "File Saved")
} else {
print("An Error Occurred! \(error)")
self.showAlert("Google Drive", message: "Sorry, an error occurred!")
}
})
}
please help me if any project is available?
Upvotes: 1
Views: 481
Reputation: 554
You can use
GTLQueryDrive *query = [GTLQueryDrive queryForFilesCreateWithObject:metadata uploadParameters:uploadParameters];
Upvotes: 0
Reputation: 31
Use
let query = GTLQueryDrive.queryForFilesCreateWithObject(file, uploadParameters: uploadParameters) as GTLQueryDrive
Upvotes: 3