Last active
August 29, 2015 14:07
-
-
Save atkit/2e651db9ffeebc635f88 to your computer and use it in GitHub Desktop.
iOS8 Push Notifications Tricks (Category)
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
#import <UIKit/UIKit.h> | |
@interface UIApplication (Notifications) | |
- (void) registerForAllNotificationTypes; | |
@end |
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
#import "UIApplication+Notifications.h" | |
@implementation UIApplication (Notifications) | |
- (UIUserNotificationSettings*) createUserNotificationSettings | |
{ | |
UIUserNotificationType userNotificationTypes = ( UIUserNotificationTypeSound | |
| UIUserNotificationTypeAlert | |
| UIUserNotificationTypeBadge); | |
return [UIUserNotificationSettings settingsForTypes:userNotificationTypes | |
categories:nil]; | |
} | |
- (void) registerForAllNotificationTypes | |
{ | |
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_8_0 | |
if ([self respondsToSelector:@selector(registerUserNotificationSettings:)]) { | |
[self registerUserNotificationSettings:[self createUserNotificationSettings]]; | |
[self registerForRemoteNotifications]; | |
} else | |
#endif | |
{ | |
[self registerForRemoteNotificationTypes: UIRemoteNotificationTypeBadge | |
| UIRemoteNotificationTypeAlert | |
| UIRemoteNotificationTypeSound]; | |
} | |
} | |
@end |
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
#import "UIApplication+Notifications.h" | |
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { | |
[application registerForAllNotificationTypes]; | |
// some other logic can be here | |
return YES; | |
} | |
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { | |
// now you have deviceToken | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment