hatim haffane hatim haffane - 10 months ago 119
iOS Question

Google Drive iOS SDK: Display Cancel Login Button

I'm working on a iOS Application and i use Google drive to access my files , login and listing file works fine , but I'm just asking how i can add a cancel button on the Login interface provided by Google drive sdk see the Image bellow

enter image description here

As,you see there are no way to do a

or a
go back

Here Is my code

// verify if the user is already connected or not
- (void)checkIfIsConnected
// Check for authorization.
GTMOAuth2Authentication *auth =
[GTMOAuth2ViewControllerTouch authForGoogleFromKeychainForName:kKeychainItemName
if ([auth canAuthorize]) {
[self isAuthorizedWithAuthentication:auth];
[self ConnectToDrive];

- (GTLServiceDrive *)driveService {
static GTLServiceDrive *service = nil;
if (!service) {

service = [[GTLServiceDrive alloc] init];
// Have the service object set tickets to fetch consecutive pages
// of the feed so we do not need to manually fetch them.
service.shouldFetchNextPages = YES;
// Have the service object set tickets to retry temporary error conditions
// automatically.
service.retryEnabled = YES;
return service;

-(void) ConnectToDrive{
SEL finishedSelector = @selector(viewController:finishedWithAuth:error:);
GTMOAuth2ViewControllerTouch *authViewController =
[[GTMOAuth2ViewControllerTouch alloc] initWithScope:kGTLAuthScopeDrive
[self.fileManagementViewController presentModalViewController:authViewController animated:YES];

// Action executed after finishing the Authentication
- (void)viewController:(GTMOAuth2ViewControllerTouch *)viewController
finishedWithAuth:(GTMOAuth2Authentication *)auth
error:(NSError *)error {
[self.fileManagementViewController dismissModalViewControllerAnimated:YES];
if (error == nil) {
[self isAuthorizedWithAuthentication:auth];

- (void)isAuthorizedWithAuthentication:(GTMOAuth2Authentication *)auth {
[[self driveService] setAuthorizer:auth];
self.isAuthorized = YES;
[self loadDriveFiles];

so what wrong ??


Please follow the steps -

enter image description here

Go to--> GTLSource->Common->OAuth2->Touch-->GTMOAuth2ViewControllerTouch.m

[self setUpNavigation];

[self.navigationController.navigationBar setTitleTextAttributes:@   {NSForegroundColorAttributeName : [UIColor blueColor]}];
self.navigationController.navigationBar.translucent = NO;

UINavigationBar *naviBarObj = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 63)];
[self.view addSubview:naviBarObj];

UIBarButtonItem *cancelItem = [[UIBarButtonItem alloc]initWithTitle:[NSString stringWithFormat:NSLocalizedString(@"Cancel", nil)] style:UIBarButtonItemStyleBordered target:self
UINavigationItem *navigItem = [[UINavigationItem alloc] initWithTitle:@"Google Drive"];
navigItem.rightBarButtonItem = cancelItem;
naviBarObj.items = [NSArray arrayWithObjects: navigItem,nil];    

  [self dismissViewControllerAnimated:YES completion:^(void){}];

-(void)setUpNavigation // Default Method Available 
 rightBarButtonItem_.customView = navButtonsView_;
 self.navigationItem.rightBarButtonItem = rightBarButtonItem_;

Once you add the above changes in the GTMOAuth2ViewControllerTouch.m and run it. you will get cancel button like this-

enter image description here

Happy Coding......!!