如何在谷歌登录界面中放置导航栏?

时间:2015-07-11 13:13:37

标签: ios

因为如果用户不想登录,则无法返回上一个屏幕,用户必须要杀死该应用程序。

enter image description here

2 个答案:

答案 0 :(得分:3)

确保您的UIWebView位于具有UINavigationController的视图控制器中。我怀疑你以模态方式呈现你的登录屏幕(通过故事板或以编程方式) - 尝试将其推送到导航堆栈上。

编辑:这是我在QEFilesListViewController中的代码:

GTMOAuth2ViewControllerTouch *authViewController =
[[GTMOAuth2ViewControllerTouch alloc] initWithScope:kGTLAuthScopeDriveFile
                                           clientID:kClientId
                                       clientSecret:kClientSecret
                                   keychainItemName:kKeychainItemName
                                           delegate:self
                                   finishedSelector:finishedSelector];
[self presentViewController:authViewController
                   animated:YES
                 completion:nil];

如果您将最后一个语句更改为

    [self.navigationController pushViewController:authViewController animated:YES];

你会得到一个后退按钮:

enter image description here

我知道当你按下后退按钮时,它会再次自动显示登录界面。我想如果你想在你自己的应用程序中实现它,你可以采取适当的措施来确保不会发生这种情况。

答案 1 :(得分:2)

尝试下面的代码。这个补丁解决了我的问题。

GTMOAuth2ViewControllerTouch *authViewController = [GTMOAuth2ViewControllerTouch controllerWithScope:kGTLAuthScopeDrive
                                                                                                    clientID:GoogleDriveClientID
                                                                                                clientSecret:GoogleDriveClientSecret
                                                                                            keychainItemName:GoogleDriveKeychainItemName
                                                                                           completionHandler:authCompletionHandler];

        UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:authViewController];
        navigationController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
        [rootController presentViewController:navigationController animated:YES completion:nil];

        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Cancel", nil)
                                                                             style:UIBarButtonItemStylePlain
                                                                            target:self
                                                                            action:@selector(didCanceledAuthorization)];
            authViewController.navigationItem.rightBarButtonItem = nil;
            authViewController.navigationItem.leftBarButtonItem = cancelButton;
            authViewController.navigationItem.title = @"Google Drive";
        });