Created
January 14, 2015 19:35
-
-
Save jeremiegirault/c179752b93e0ea4fc4f0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { | |
// show main window | |
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; | |
self.home = [[HomeViewController alloc] init]; | |
UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.home]; | |
[self.window setRootViewController:nav]; | |
[self.window makeKeyAndVisible]; | |
// register for push if needed | |
UIUserNotificationSettings* settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert categories:[NSSet set]]; | |
[application registerUserNotificationSettings:settings]; | |
// handle push when app started by clicking on the notification | |
[self handlePush:[launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]]; | |
// display local notification (for exemple) | |
UILocalNotification* localNotif = [[UILocalNotification alloc] init]; | |
[localNotif setAlertBody:@"Discover this notification !"]; | |
[localNotif setFireDate:[NSDate dateWithTimeIntervalSinceNow:10]]; | |
[localNotif setUserInfo:@{ @"rpm": @"Would you want to participate to the contest ?", @"rpu": @"http://www.google.fr" }]; | |
[application scheduleLocalNotification:localNotif]; | |
return YES; | |
} | |
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { | |
[self handlePush:userInfo]; | |
} | |
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { | |
[self handlePush:[notification userInfo]]; | |
} | |
// core notification handling | |
-(void)handlePush:(NSDictionary*)userInfo { | |
if (userInfo[@"rpu"]) { | |
/* if (userInfo[@"rpm"]) { | |
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"MYAPP" message:userInfo[@"rpm"] delegate:nil cancelButtonTitle:@"NO" otherButtonTitles:@"GO", nil]; | |
[[alert rac_buttonClickedSignal] subscribeNext:^(NSNumber* x) { | |
if ([x integerValue] == 1) { | |
dispatch_async(dispatch_get_main_queue(), ^{ | |
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:userInfo[@"rpu"]]]; | |
}); | |
} | |
}]; | |
[alert show]; | |
} else {*/ | |
// dispatch async handles ios bug cf. my answer on stackoverflow http://stackoverflow.com/questions/19356488/openurl-freezes-app-for-over-10-seconds/19791965#19791965 | |
dispatch_async(dispatch_get_main_queue(), ^{ | |
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:userInfo[@"rpu"]]]; | |
}); | |
//} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment