Skip to content

Commit

Permalink
Handle launching from a notification, clear notifications on launch
Browse files Browse the repository at this point in the history
  • Loading branch information
c99koder committed May 29, 2013
1 parent 79aceea commit 462ce0c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
4 changes: 2 additions & 2 deletions IRCCloud/Classes/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

@property (strong, nonatomic) UIWindow *window;

@property (strong, nonatomic) UIViewController *loginSplashViewController;
@property (strong, nonatomic) UIViewController *mainViewController;
@property (strong, nonatomic) LoginSplashViewController *loginSplashViewController;
@property (strong, nonatomic) MainViewController *mainViewController;

-(void)showLoginView;
-(void)showMainView;
Expand Down
23 changes: 14 additions & 9 deletions IRCCloud/Classes/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
self.loginSplashViewController = [[LoginSplashViewController alloc] initWithNibName:@"LoginSplashViewController_iPad" bundle:nil];
self.mainViewController = [[MainViewController alloc] initWithNibName:@"MainViewController_iPad" bundle:nil];
}
if(launchOptions && [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]) {
self.mainViewController.bidToOpen = [[[[launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey] objectForKey:@"d"] objectAtIndex:1] intValue];
}
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showMainView) name:kIRCCloudBacklogCompletedNotification object:nil];
self.window.rootViewController = self.loginSplashViewController;
[self.window makeKeyAndVisible];
Expand All @@ -40,6 +43,13 @@ - (void)application:(UIApplication *)app didFailToRegisterForRemoteNotifications
TFLog(@"Error in APNs registration. Error: %@", err);
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
NSLog(@"** remote: %@", userInfo);
if(_disconnectTimer) {
[self.mainViewController bufferSelected:[[[userInfo objectForKey:@"d"] objectAtIndex:1] intValue]];
}
}

-(void)showLoginView {
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showMainView) name:kIRCCloudBacklogCompletedNotification object:nil];
Expand Down Expand Up @@ -86,16 +96,11 @@ - (void)applicationWillResignActive:(UIApplication *)application {
});
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
[self applicationWillResignActive:application];
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
[self applicationDidBecomeActive:application];
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
[_disconnectTimer performSelectorOnMainThread:@selector(invalidate) withObject:nil waitUntilDone:YES];
application.applicationIconBadgeNumber = 1;
application.applicationIconBadgeNumber = 0;
[application cancelAllLocalNotifications];
[_disconnectTimer invalidate];
_disconnectTimer = nil;
if([self.window.rootViewController isKindOfClass:[ECSlidingViewController class]]) {
ECSlidingViewController *evc = (ECSlidingViewController *)self.window.rootViewController;
Expand Down
2 changes: 1 addition & 1 deletion IRCCloud/Classes/EventsTableView.m
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ - (void)backlogCompleted:(NSNotification *)notification {
- (void)_sendHeartbeat {
NSTimeInterval eid = [[[[EventsDataSource sharedInstance] eventsForBuffer:_buffer.bid] lastObject] eid];
if(eid > _buffer.last_seen_eid) {
//[_conn heartbeat:_buffer.bid cid:_buffer.cid bid:_buffer.bid lastSeenEid:eid];
[_conn heartbeat:_buffer.bid cid:_buffer.cid bid:_buffer.bid lastSeenEid:eid];
_buffer.last_seen_eid = eid;
}
_heartbeatTimer = nil;
Expand Down
3 changes: 3 additions & 0 deletions IRCCloud/Classes/MainViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@
UIView *_barButtonContainer;
NSTimer *_doubleTapTimer;
NSMutableArray *_pendingEvents;
int _bidToOpen;
}
@property (nonatomic) int bidToOpen;
-(void)bufferSelected:(int)bid;
-(void)sendButtonPressed:(id)sender;
-(void)usersButtonPressed:(id)sender;
-(void)listButtonPressed:(id)sender;
Expand Down
5 changes: 5 additions & 0 deletions IRCCloud/Classes/MainViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
_cidToOpen = -1;
_bidToOpen = -1;
_pendingEvents = [[NSMutableArray alloc] init];
}
return self;
Expand Down Expand Up @@ -113,6 +114,10 @@ - (void)viewDidLoad {
if([[BuffersDataSource sharedInstance] getBuffer:[[[NetworkConnection sharedInstance].userInfo objectForKey:@"last_selected_bid"] intValue]])
bid = [[[NetworkConnection sharedInstance].userInfo objectForKey:@"last_selected_bid"] intValue];
}
if(_bidToOpen != -1) {
bid = _bidToOpen;
_bidToOpen = -1;
}
[self bufferSelected:bid];
}

Expand Down

0 comments on commit 462ce0c

Please sign in to comment.