10 ipad ios ios5 google-drive-api
我正在使用iOS应用程序,我使用谷歌驱动器访问我的文件,登录和列表文件工作正常,但我只是问我如何在登录界面上添加取消按钮由谷歌驱动器sdk提供查看图像怒吼

因为,你看到没有办法做一个cancel或一个go back按钮.
这是我的代码
// 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];
}
Run Code Online (Sandbox Code Playgroud)
怎么了?
Che*_*ile 24
请按照步骤 -

转到 - > 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_;
}
Run Code Online (Sandbox Code Playgroud)
在GTMOAuth2ViewControllerTouch.m中添加上述更改并运行它.你会得到这样的取消按钮 -

快乐的编码...... !!
小智 12
改变来源 - 糟糕的方式.这是我的解决方案.适用于iPhone和iPad
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";
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4092 次 |
| 最近记录: |