Google Drive iOS SDK:显示取消登录按钮 [英] Google Drive iOS SDK: Display Cancel Login Button
问题描述
我正在开发iOS应用程序,我使用Google驱动器来访问我的文件,登录和列表文件工作正常,但我只是问如何在Google驱动器sdk提供的登录界面上添加取消按钮看到图像波纹管
由于您看不到取消
或返回
按钮。
这是我的代码
//验证用户是否已连接
- (void)checkIfIsConnected
{
//检查授权。
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];
//让服务对象设置票据以获取Feed的连续页面
//,因此我们不需要手动获取它们。
service.shouldFetchNextPages = YES;
//让服务对象设置票据以自动重试临时错误条件
//。
service.retryEnabled = YES;
}
退货服务;
}
- (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];
}
//完成认证后执行的动作
- (void)viewController:(GTMOAuth2ViewControllerTouch *)viewController
finishedWithAuth:(GTMOAuth2Authentication *)auth
错误:(NSError *)错误{
[self.fileManagementViewController dismissModalViewControllerAnimated:YES];
if(error == nil){
[self isAuthorizedWithAuthentication:auth];
$ b - (void)isAuthorizedWithAuthentication:(GTMOAuth2Authentication *)auth {
[[self driveService] setAuthorizer:auth];
self.isAuthorized = YES;
[self loadDriveFiles];
}
所以错了什么?
请按照以下步骤操作 -
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];
$ b - (void)cancelGdriveSignIn:(id)sender
{
[self dismissViewControllerAnimated:YES completion:^(void){}];
- (void)setUpNavigation //可用的缺省方法
{
rightBarButtonItem_.customView = navButtonsView_;
self.navigationItem.rightBarButtonItem = rightBarButtonItem_;
}
在GTMOAuth2ViewControllerTouch.m中添加上述更改并运行它。你会得到像这样的取消按钮 -
<快乐编码...... !!
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
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 ??
Please follow the steps -
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-
Happy Coding......!!
这篇关于Google Drive iOS SDK:显示取消登录按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!