Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
459 views
in Technique[技术] by (71.8m points)

ipad - 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 cancel or a go back button.

Here Is my code

// verify if the user is already connected or not 
    - (void)checkIfIsConnected
    {
        // Check for authorization.
        GTMOAuth2Authentication *auth =
        [GTMOAuth2ViewControllerTouch authForGoogleFromKeychainForName:kKeychainItemName
                                                              clientID:kClientID
                                                          clientSecret:kClientSecret];
        if ([auth canAuthorize]) {
            [self isAuthorizedWithAuthentication:auth];
        }else
        {
            [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
                                                   clientID:kClientID
                                               clientSecret:kClientSecret
                                           keychainItemName:kKeychainItemName
                                                   delegate:self
                                           finishedSelector:finishedSelector];
        [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 ??

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Please follow the steps -

enter image description here

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

-(void)viewDidLoad
{
[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
                                                             action:@selector(cancelGdriveSignIn:)];    
UINavigationItem *navigItem = [[UINavigationItem alloc] initWithTitle:@"Google Drive"];
navigItem.rightBarButtonItem = cancelItem;
naviBarObj.items = [NSArray arrayWithObjects: navigItem,nil];    
}

 -(void)cancelGdriveSignIn:(id)sender
 {
  [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......!!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...