Skip to content

Instantly share code, notes, and snippets.

@yelirekim
Created November 16, 2010 00:30
Show Gist options
  • Save yelirekim/701237 to your computer and use it in GitHub Desktop.
Save yelirekim/701237 to your computer and use it in GitHub Desktop.
Attempting to transition between views, replacing the entire view stack, using TTNavigator
@implementation assassinsAppDelegate
- (id)init {
self = [super init];
if(self) {
animationMarker = NO;
}
return self;
}
- (void)applicationDidFinishLaunching:(UIApplication *)application {
_locationManager = [[LocationManager alloc] init];
_locationManager.delegates = [NSArray arrayWithObject:self];
[_locationManager load:TTURLRequestCachePolicyNone more:YES];
[TTStyleSheet setGlobalStyleSheet:[[[StyleSheet alloc] init] autorelease]];
TTNavigator * navigator = [TTNavigator navigator];
navigator.persistenceMode = TTNavigatorPersistenceModeAll;
TTURLMap * map = navigator.URLMap;
[map from:@"*" toViewController:[TTWebController class]];
[GameController map:map];
[map from:kLoginURLPath toSharedViewController:[AuthenticationController class]];
[map from:kGamesListURLPath toSharedViewController:[GamesListController class]];
[map from:kAppRootURLPath toSharedViewController:[AssassinsRootViewController class]];
[map from:kAccountURLPath toSharedViewController:[AccountController class]];
if (![navigator restoreViewControllers]) {
[self authenticate:NO];
}
}
- (void)applicationDidFinishLaunching:(UIApplication *)application withOptions:(NSDictionary *)options {
if([options objectForKey:UIApplicationLaunchOptionsLocationKey] != nil) {
if(_locationManager == nil) {
_locationManager = [[LocationManager alloc] init];
}
[_locationManager load:TTURLRequestCachePolicyNone more:NO];
}
}
- (void)authenticationCredentialsObtained:(NSString *)authToken userId:(NSNumber *)userId {
[AssassinsUser setAuthenticationToken:authToken];
[self authenticate:YES];
}
- (void)authenticate:(BOOL)animated {
TTNavigator * navigator = [TTNavigator navigator];
[navigator removeAllViewControllers];
if([AssassinsUser authenticationToken] == nil) {
TTURLAction * action = [TTURLAction actionWithURLPath:kLoginURLPath];
if(animated) {
[action applyAnimated:UIViewAnimationTransitionFlipFromRight];
}
[navigator openURLAction:action];
} else {
TTURLAction * action = [TTURLAction actionWithURLPath:kAppRootURLPath];
if(animated) {
[action applyAnimated:UIViewAnimationTransitionFlipFromLeft];
}
[navigator openURLAction:action];
}
}
- (void)logout:(BOOL)animated {
[AssassinsUser setAuthenticationToken:nil];
[self authenticate:animated];
}
- (BOOL)navigator:(TTNavigator*)navigator shouldOpenURL:(NSURL*)URL {
return YES;
}
- (BOOL)application:(UIApplication*)application handleOpenURL:(NSURL*)URL {
[[TTNavigator navigator] openURLAction:[TTURLAction actionWithURLPath:URL.absoluteString]];
return YES;
}
- (void)dealloc {
TT_RELEASE_SAFELY(_locationManager);
[super dealloc];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment