iOS-Using upload image on Google Drive Api(error "Assertion failure in: GTLServer...") - ios

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.

Related

Custom Migration corrupts db

When I try to migrate my old db to a new db, it is all done correctly. But when I try to access the db, it says its corrupted or malformed. It happens only in iOS11.
I get this error -
error: exception handling request: <NSSQLRelationshipFaultRequestContext: 0x1c4cbc9e0> , Fatal error. The database at /var/mobile/Containers/Data/Application/743F0953-2F57-4B9F-931A-0E0AEF9E8D0A/Documents/Main.db is corrupted. SQLite error code:11, 'database disk image is malformed' with userInfo of {
NSFilePath = "/var/mobile/Containers/Data/Application/743F0953-2F57-4B9F-931A-0E0AEF9E8D0A/Documents/Main.db";
NSSQLiteErrorDomain = 11;
}
When I try accessing db, I get -
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Object's persistent store is not reachable from this NSManagedObjectContext's coordinator'
This is my code of migration -
NSError *error = nil;
NSMappingModel *mapping = [NSMappingModel inferredMappingModelForSourceModel: oldModel destinationModel: self error: &error];
if (error) {
LOG(#"Error while inferring mapping model: %#", error);
return NO;
}
NSString *newContextPath = [contextPath stringByAppendingPathExtension: #"tmp"];
NSValue *classValue = [[NSPersistentStoreCoordinator registeredStoreTypes] objectForKey: NSSQLiteStoreType];
Class sqliteStoreClass = (Class)[classValue pointerValue];
Class sqliteStoreMigrationManagerClass = [sqliteStoreClass migrationManagerClass];
NSURL *srcURL = [NSURL fileURLWithPath: contextPath], *dstURL = [NSURL fileURLWithPath: newContextPath];
NSMigrationManager *manager = [[sqliteStoreMigrationManagerClass alloc] initWithSourceModel: oldModel destinationModel: self];
#try {
if (![manager migrateStoreFromURL: srcURL type:NSSQLiteStoreType options:nil withMappingModel:mapping toDestinationURL: dstURL destinationType:NSSQLiteStoreType destinationOptions:nil error:&error]) {
LOG(#"Migration failed %#", error);
return NO;
}
} #catch (NSException *exception) {
LOG(#"Exception: %#", exception);
return NO;
}
if (![[NSFileManager defaultManager] removeItemAtPath: contextPath error: &error]) {
LOG(#"Error removing old database: %#", error);
return NO;
}
if (![[NSFileManager defaultManager] moveItemAtPath: newContextPath toPath: contextPath error: &error]) {
LOG(#"Error renaming/moving new database: %#", error);
return NO;
}
LOG(#"- Context Migration: Complete");
I finally found out, I was deleting only .db file but not .shm and .wal files. This was okay with iOS10 and below, but somehow corrupts the db in iOS11. So, deleted both the old .shm and .wal files fixed the issue.
If anyone struggling what is going wrong, this might be of some help.

Google calendar API add calendar for objective-c

How to use google calendar list insert with Objective-C.
https://developers.google.com/google-apps/calendar/v3/reference/calendarList/insert#response
I want add a public calendar[ID:b3b9bke782agahkklrqujdhi74#group.calendar.google.com]
to my calendar but there is some error
Error Domain=com.google.GTLJSONRPCErrorDomain Code=**403** "(Insufficient Permission)" UserInfo={error=Insufficient Permission, NSLocalizedFailureReason=(Insufficient Permission), GTLStructuredError=GTLErrorObject 0x7f9b40d0da00: {message:"Insufficient Permission" data:[1] code:403}}
2016-03-10 17:34:23.022 calendar20160225[10337:413037] error:(null)
I edit from https://developers.google.com/google-apps/calendar/quickstart/ios
I add this and got the error
-(void)myCalendarQuery
{
NSString* enter code herenewCalendarName=#"b3b9bke782agahkklrqujdhi74#group.calendar.google.com";
GTLCalendarCalendarListEntry *entry=[GTLCalendarCalendar object];
GTLServiceCalendar *service = self.service;
GTLCalendarCalendar *newEntry = [GTLCalendarCalendar object];
newEntry.summary = newCalendarName;
newEntry.timeZone = [[NSTimeZone localTimeZone] name];
GTLQueryCalendar *query = [GTLQueryCalendar queryForCalendarsInsertWithObject:newEntry];
GTLServiceTicket* editCalendarListTicket =[[GTLServiceTicket alloc]init];
[self.service executeQuery:query
delegate:self
didFinishSelector:#selector(displayResultWithTicket:finishedWithObject:error:)];
editCalendarListTicket = [service executeQuery:query
completionHandler:^(GTLServiceTicket *ticket, id object, NSError *error) {
// Callback
//editCalendarListTicket = nil;
if (error == nil) {
[self fetchCalendarList];
} else {
NSLog(#"error:%#",error);
[self fetchCalendarList];
[self showAlert:#"Add failed" message:[NSString stringWithFormat:#"Calendar add failed: %#", error]];
}
}];
//b3b9bke782agahkklrqujdhi74#group.calendar.google.com
GTLQueryCalendar *query2 = [GTLQueryCalendar queryForEventsListWithCalendarId:#"b3b9bke782agahkklrqujdhi74#group.calendar.google.com"];
[GTLQueryCalendar queryForEventsInsertWithObject:query calendarId:#"b3b9bke782agahkklrqujdhi74#group.calendar.google.com"];
query.maxResults = 10;
query.timeMin = [GTLDateTime dateTimeWithDate:[NSDate date]
timeZone:[NSTimeZone localTimeZone]];;
query.singleEvents = YES;
query.orderBy = kGTLCalendarOrderByStartTime;
[self.service executeQuery:query
delegate:self
didFinishSelector:#selector(displayResultWithTicket:finishedWithObject:error:)];
// [GTLQueryCalendar queryForAclInsertWithObject:query calendarId:#"b3b9bke782agahkklrqujdhi74#group.calendar.google.com"];
}
This is working.
-(void)getCalendar
{
NSString* newCalendarName = #"b3b9bke782agahkklrqujdhi74#group.calendar.google.com";
GTLQueryCalendar *query2 = [GTLQueryCalendar queryForCalendarsGetWithCalendarId:newCalendarName];
[self.service executeQuery:query2
delegate:self
didFinishSelector:#selector(displayResultWithTicket2:finishedWithObject:error:)];
}
But if I want to add something into my calendar.It will not work.I thing maybe problem is that I need scope kGTLAuthScopeCalendar to have read/write access. (I just find from Add event to google calendar from ios. Also note, that you have to authorize with the answer to said scope kGTLAuthScopeCalendar to have read/write access.)
I fix the problem .My scope only calendarRealOnly.
I finally add https://www.googleapis.com/auth/calendar.
[self.googleOAuth authorizeUserWithClienID:#"clienID"
andClientSecret:#"clentSecret"
andParentView:self.view
andScopes:[NSArray arrayWithObjects:
#"https://www.googleapis.com/auth/userinfo.profile",
#"https://www.googleapis.com/auth/calendar",
#"https://www.googleapis.com/auth/calendar.readonly",
nil]
];
GTLCalendarCalendarListEntry*calendarListEntry=[GTLCalendarCalendarListEntry object];
calendarListEntry.identifier = #"b3b9bke782agahkklrqujdhi74#group.calendar.google.com";
GTLQueryCalendar *queryInsertCalendarList = [GTLQueryCalendar queryForCalendarListInsertWithObject:calendarListEntry];
[self.service executeQuery:queryInsertCalendarList
delegate:self
didFinishSelector:nil];

Upload file to Google Drive with apiKey on ios

I'm trying to upload an image to Google Drive to my own account (not user account) so I don't need to ask for permissions to the user. To do so I'm using the apiKey instead of oAuth2 method.
The problem is that when I'm sending the file to Google the error I get is 'Login required' but I want to log in, that's why I use apiKey.
GTLServiceDrive *driveService = [[GTLServiceDrive alloc] init];
[driveService setAPIKey:#"this-Is-My-APIKey"];
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 imageNamed:#"this-Is-My-Image"]);
GTLUploadParameters *uploadParameters = [GTLUploadParameters uploadParametersWithData:data MIMEType:file.mimeType];
GTLQueryDrive *query = [GTLQueryDrive queryForFilesInsertWithObject:file uploadParameters:uploadParameters];
GTLServiceTicket *queryTicket =
[driveService executeQuery:query
completionHandler:^(GTLServiceTicket *ticket,
GTLDriveFile *insertedFile, NSError *error) {
if (error == nil) {
// Uncomment the following line to print the File ID.
NSLog(#"File ID: %#", insertedFile.identifier);
} else {
NSLog(#"An error occurred: %#", error);
}
}];
This is the error I get:
An error occurred: Error Domain=com.google.GTLJSONRPCErrorDomain Code=401 "The operation couldn’t be completed. (Login Required)" UserInfo=0x7ffa12d14eb0 {error=Login Required, NSLocalizedFailureReason=(Login Required), GTLStructuredError=GTLErrorObject 0x7ffa12d2d8a0: {message:"Login Required" data:[1] code:401}}
Makes any sense what I'm trying to do? Any help will be welcome, thanks!!

Google Drive MIME types iOS

I'm trying to integrate Google Drive API with my iOS application. I'm unable to download files, however, and I think it has to do with the MIME type. In the API console I set the MIME types like so:
And I download files with the following code:
GTLQueryDrive *query = [GTLQueryDrive queryForFilesList];
query.q = #"mimeType = 'text/plain'";
[self.driveService executeQuery:query completionHandler:^(GTLServiceTicket *ticket,
GTLDriveFileList *files,
NSError *error) {
if (error == nil) {
if (self.googleDriveFiles == nil) {
self.googleDriveFiles = [[NSMutableArray alloc] init];
}
[self.googleDriveFiles removeAllObjects];
[self.googleDriveFiles addObjectsFromArray:files.items];
NSLog(#"files: %#",self.googleDriveFiles);
[self.noteTableview reloadData];
} else {
NSLog(#"An error occurred: %#", error);
//[DrEditUtilities showErrorMessageWithTitle:#"Unable to load files"
// message:[error description]
// delegate:self];
}
}];
NSLog outputs (null) What's wrong here?

xcode running well on simulator but when deploy to ios 6 encounter error

2012-10-08 14:48:14.579 sageby[2716:907] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SBJsonParser errorTrace]: unrecognized selector sent to instance 0x1fda4660'
* First throw call stack:
(0x352412a3 0x34a1397f 0x35244e07 0x35243531 0x3519af68 0x12932f 0x1293a7 0x12cda3 0x12c9b1 0x12c753 0x12aac7 0x12e567 0x12eac3 0x3a26bef5 0x3a1ab9f1 0x3a1ab90d 0x384ba5df 0x384b9ccb 0x384e2133 0x3518774d 0x384e2593 0x3844615d 0x35216683 0x35215ee9 0x35214cb7 0x35187ebd 0x35187d49 0x35ef02eb 0x37dcd301 0xaaaf1 0x39e0cb20)
libc++abi.dylib: terminate called throwing an exception
(lldb)
//MBProgressHUD
MBProgressHUD *hud=[MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.labelText=#"Accessing account..";
hud.labelFont=[UIFont fontWithName:#"Arial Rounded MT Bold" size:14];
//URL GETTING
NSString *phpfile=[[NSString alloc]initWithFormat:#"http://dev.xxxx.com/pxxx/Module_MyPxxx/json_xxxx_xxx_info.php"];
NSString *param_str=[[NSString alloc]initWithFormat:#"email=%#", mydelegate.overall_email];
NSString *receivedDataAsString=[mydelegate phpConnection:param_str :phpfile];
SBJsonParser *parser=[[SBJsonParser alloc]init];
NSError *error=nil;
self.dic_user_info=[[parser objectWithString:receivedDataAsString error:&error]objectAtIndex:0];
if(error)
{
NSLog(#"JSON Parser error! Reason: %#", error.localizedDescription);
}
//URL GETTING
phpfile=[[NSString alloc]initWithFormat:#"http://dev.xxx.com/pxxx/Module_MyPxxx/json_get_xxx_xxx_pxxx.php"];
param_str=[[NSString alloc]initWithFormat:#"email=%#", mydelegate.overall_email];
receivedDataAsString=[mydelegate phpConnection:param_str :phpfile];
parser=[[SBJsonParser alloc]init];
error=nil;
self.array_polls=[parser objectWithString:receivedDataAsString error:&error];
if(error)
{
NSLog(#"JSON Parser error! Reason: %#", error.localizedDescription);
}
[self.tableView reloadData];
[MBProgressHUD hideHUDForView:self.view animated:YES];
hi i'm the developer of the application.
The problem is that running on Xcode 4.5 is correct but just running on iphone device it wont work..

Resources