Skip to content

Instantly share code, notes, and snippets.

@skabber
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skabber/d1ff80669f86c5f5f378 to your computer and use it in GitHub Desktop.
Save skabber/d1ff80669f86c5f5f378 to your computer and use it in GitHub Desktop.
Push registration
- (void)updateAlerts
{
BOOL alertsMaster = [[NSUserDefaults standardUserDefaults] boolForKey:kAlertsMasterSwitch];
BOOL alertsSounds = [[NSUserDefaults standardUserDefaults] boolForKey:kAlertsSoundSwitch];
BOOL alertsBadge = [[NSUserDefaults standardUserDefaults] boolForKey:kAlertsBadgeSwitch];
if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) {
UIUserNotificationType alert = UIUserNotificationTypeNone;
UIUserNotificationType sound = UIUserNotificationTypeNone;
UIUserNotificationType badge = UIUserNotificationTypeNone;
if (alertsMaster == YES) {
alert = UIUserNotificationTypeAlert;
}
if (alertsSounds == YES) {
sound = UIUserNotificationTypeSound;
}
if (alertsBadge == YES) {
badge = UIUserNotificationTypeBadge;
}
UIUserNotificationType finalTypes = alert|sound|badge;
// This should eventually call back to application:didRegisterForRemoteNotificationsWithDeviceToken:
[[PushIOManager sharedInstance] registerForRemoteNotificationWithSettings:[UIUserNotificationSettings settingsForTypes:finalTypes categories:nil]];
} else {
UIRemoteNotificationType alert = UIRemoteNotificationTypeNone;
UIRemoteNotificationType sound = UIRemoteNotificationTypeNone;
UIRemoteNotificationType badge = UIRemoteNotificationTypeNone;
if (alertsMaster == YES) {
alert = UIRemoteNotificationTypeAlert;
}
if (alertsSounds == YES) {
sound = UIRemoteNotificationTypeSound;
}
if (alertsBadge == YES) {
badge = UIRemoteNotificationTypeBadge;
}
UIRemoteNotificationType finalTypes = alert|sound|badge;
// This should eventually call back to application:didRegisterForRemoteNotificationsWithDeviceToken:
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:finalTypes];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment