Using GTMOAuth2ViewControllerTouch as a modal view instead of pushing it as a navcontroller view

1,519 views
Skip to first unread message

Zak

unread,
Jul 18, 2012, 7:39:07 AM7/18/12
to gtm-o...@googlegroups.com
How can I adapt or subclass GTMOAuth2ViewControllerTouch to use as a modal view? Currently I have it opening ok, but it fails at a few key places (for example, it doesn't auto-close when it reaches the authorization success page.). What steps do I need to take to make it work as a modal view?

David Phillip Oster (☃)

unread,
Jul 18, 2012, 1:46:16 PM7/18/12
to gtm-o...@googlegroups.com
Where the sample app calls:

  [[self navigationController] pushViewController:viewController animated:YES];


instead call:

   MyNavigationController *presentModal = [[[MyNavigationController alloc] initWithRootViewController:viewController] autorelease];

  [presentModal setDismisser:self];

  UIBarButtonItem *cancelButton = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(doDismiss)] autorelease];

  [[viewController navigationItem] setLeftBarButtonItem:cancelButton];

  [[self navigationController] presentModalViewController:presentModal animated:YES];


where doDismiss is:

- (void)doDismiss {

  [self dismissModalViewControllerAnimated:YES];

}


that handles showing and canceling. 

For auto-dismiss, we catch the pop that the OAuth2ViewController will do:

@interface MyNavigationController : UINavigationController
@property (nonatomic, assign) UIViewController *dismisser;
- (UIViewController *)popViewControllerAnimated:(BOOL)animated;
@end
@implementation MyNavigationController
@synthesize dismisser;
- (UIViewController *)popViewControllerAnimated:(BOOL)animated {
  if ([[self viewControllers] count] <= 1) {
    UIViewController *result = [[[self topViewController] retain] autorelease];
    [dismisser dismissModalViewControllerAnimated:YES];
    return result;
  } else {
    return [super popViewControllerAnimated:animated];
  }
}
@end

Warning: I didn't actually try the auto-dismiss case.

Greg Robbins

unread,
Jul 28, 2012, 2:21:59 AM7/28/12
to gtm-o...@googlegroups.com
We have recently added a property to the gtm-oauth2 iOS view controller, popViewBlock, which is a block the app can set that will be called when the view should be removed. You may find that helpful.

Greg Robbins

unread,
Oct 30, 2012, 4:40:22 PM10/30/12
to gtm-o...@googlegroups.com
The popViewBlock should be called immediately and the kGTMOAuth2UserSignedIn notification posted as the controller detects the server's end-of-sign-in signals. 

It may take longer for the completion handler for auth to be called, as additional fetches are needed to obtain an access token and, for Google sign-ins, the user's email address.

Reply all
Reply to author
Forward
0 new messages