Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions DemoApp/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ @implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[application registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeBadge)];
[self registerUserNofication];
application.applicationIconBadgeNumber = 0;

[[JRNLocalNotificationCenter defaultCenter] setLocalNotificationHandler:^(NSString *key, NSDictionary *userInfo) {
Expand All @@ -27,16 +27,17 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
}
}];

if (launchOptions[UIApplicationLaunchOptionsLocalNotificationKey]) {
[[JRNLocalNotificationCenter defaultCenter] didReceiveLocalNotificationUserInfo:launchOptions[UIApplicationLaunchOptionsLocalNotificationKey]];
UILocalNotification *localNotification = launchOptions[UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotification) {
[[JRNLocalNotificationCenter defaultCenter] didReceiveLocalNotification:localNotification];
}

return YES;
}

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
[[JRNLocalNotificationCenter defaultCenter] didReceiveLocalNotificationUserInfo:notification.userInfo];
[[JRNLocalNotificationCenter defaultCenter] didReceiveLocalNotification:notification];
}

- (void)applicationWillResignActive:(UIApplication *)application
Expand Down Expand Up @@ -66,4 +67,24 @@ - (void)applicationWillTerminate:(UIApplication *)application
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

#pragma mark - Helper

- (void)registerUserNofication
{
if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]) {
UIUserNotificationSettings *settings = [UIApplication sharedApplication].currentUserNotificationSettings;
// check for user notification settings
if (settings.types == UIUserNotificationTypeNone) {
// specify notif types
UIUserNotificationType types = UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
UIUserNotificationSettings *notificationSettings = [UIUserNotificationSettings settingsForTypes:types
categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
}
}
else {
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert];
}
}

@end
2 changes: 1 addition & 1 deletion JRNLocalNotificationCenter/JRNLocalNotificationCenter.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ typedef void (^JRNLocalNotificationHandler)(NSString *key, NSDictionary *userInf


//Handling
- (void)didReceiveLocalNotificationUserInfo:(NSDictionary *)userInfo;
- (void)didReceiveLocalNotification:(UILocalNotification *)localNotification;


//Cancel
Expand Down
5 changes: 3 additions & 2 deletions JRNLocalNotificationCenter/JRNLocalNotificationCenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ - (NSArray *)localNotifications
}


- (void)didReceiveLocalNotificationUserInfo:(NSDictionary *)userInfo
- (void)didReceiveLocalNotification:(UILocalNotification *)localNotification
{
NSDictionary *userInfo = localNotification.userInfo;
NSString *key = userInfo[JRNLocalNotificationHandlingKeyName];
if (!key) {
return;
Expand All @@ -62,7 +63,7 @@ - (void)didReceiveLocalNotificationUserInfo:(NSDictionary *)userInfo
userInfo:userInfo];

if (self.localNotificationHandler) {
self.localNotificationHandler(userInfo[JRNLocalNotificationHandlingKeyName], userInfo);
self.localNotificationHandler(key, userInfo);
}
}

Expand Down