Using GMTOAuth across multiple view controllers

44 views
Skip to first unread message

Mark Harding

unread,
Nov 22, 2011, 4:51:52 PM11/22/11
to GTM OAuth 1 Discussion
My app is setup where there are multiple view controllers linked to
the delegate. I have the main authentication setup to the delegate. I
have no problems authenticating the user from my loginViewController
controller however when the app reloads homeViewController says that
the user is not authenticated whilst the delegate says it is. Somehow
the controllers are not speaking to each other. In my
homeViewContoller.m file I include this code:

BOOL isSignedIn = [appDelegate.mAuth canAuthorize];
if(isSignedIn == true){
NSLog(@"signedin");
} else {
NSLog(@"notsignedin");
}

and it returns not signed in. If I use the same code in the delegate
(on app load) then it returns signed in. Any ideas?

Thanks.

Joe

unread,
Nov 22, 2011, 6:58:12 PM11/22/11
to gtm-...@googlegroups.com
Are you sure the appDelegate is set properly?  If it's not, then you'll get that result.

joe

David Phillip Oster

unread,
Nov 23, 2011, 1:04:23 PM11/23/11
to gtm-...@googlegroups.com
Rather than using a property, I prefer to use a free function, defined after the @end in my AppDelegate.h

MyAppDelegate* TheAppDelegate(void);

And after the @end in  AppDelegate.m  defined as:

MyAppDelegate* TheAppDelegate(void) {
  return (MyAppDelegate*) [[UIApplication sharedApplication] delegate];
}

then I can say:
BOOL iSignedIn = [[TheAppDelegate() mAuth] canAuthorize];

from anywhere in the program, and know it is going to the real one.
Reply all
Reply to author
Forward
0 new messages