Last active
August 29, 2015 13:56
-
-
Save jessbowers/9257846 to your computer and use it in GitHub Desktop.
App Delegate with PushIO
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 | |
{ | |
// 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]; | |
} |
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 | |
{ | |
// 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