Skip to content

Instantly share code, notes, and snippets.

@jessbowers
Last active August 29, 2015 13:56
Show Gist options
  • Save jessbowers/9257846 to your computer and use it in GitHub Desktop.
Save jessbowers/9257846 to your computer and use it in GitHub Desktop.
App Delegate with PushIO
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Push IO Setup
[[PushIOManager sharedInstance] setDelegate:self];
[[PushIOManager sharedInstance] didFinishLaunchingWithOptions:launchOptions];
// register the types we'll be sending with Apple
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound)];
}
- (void)registerForPushNotifications;
{
// save the user's choice to always show notifications
[[NSUserDefaults standardUserDefaults] setObject:@(YES) forKey:kUserSettingEnablePushNotifications];
[[NSUserDefaults standardUserDefaults] synchronize];
[[PushIOManager sharedInstance] registerWithPushIO];
}
- (void)unregisterForPushNotifications;
{
// save the user's choice not to show notifications
[[NSUserDefaults standardUserDefaults] setObject:@(NO) forKey:kUserSettingEnablePushNotifications];
[[NSUserDefaults standardUserDefaults] synchronize];
// disable notifications with PushIO
[[PushIOManager sharedInstance] unregisterFromPushIO];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Push IO Setup
[[PushIOManager sharedInstance] setDelegate:self];
[[PushIOManager sharedInstance] didFinishLaunchingWithOptions:launchOptions];
// only register when the user defaults have enabled it
if ([[[NSUserDefaults standardUserDefaults] objectForKey:kUserSettingEnablePushNotifications] boolValue]) {
[self registerForPushNotifications];
}
}
- (void)registerForPushNotifications;
{
// save the user's choice to always show notifications
[[NSUserDefaults standardUserDefaults] setObject:@(YES) forKey:kUserSettingEnablePushNotifications];
[[NSUserDefaults standardUserDefaults] synchronize];
// register the types we'll be sending with Apple
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound)];
[[PushIOManager sharedInstance] registerWithPushIO];
}
- (void)unregisterForPushNotifications;
{
// save the user's choice not to show notifications
[[NSUserDefaults standardUserDefaults] setObject:@(NO) forKey:kUserSettingEnablePushNotifications];
[[NSUserDefaults standardUserDefaults] synchronize];
// disable notifications with PushIO
[[PushIOManager sharedInstance] unregisterFromPushIO];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment