From 3749249613adaffd532f4c509e2921244507a64a Mon Sep 17 00:00:00 2001 From: Lidan Hifi Date: Wed, 13 Apr 2016 18:41:17 +0300 Subject: [PATCH] fix badge handling, added category to local notification --- RNNotifications/RNNotifications.m | 10 +++++++--- notification.ios.js | 3 +-- test/notification.ios.spec.js | 4 ++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/RNNotifications/RNNotifications.m b/RNNotifications/RNNotifications.m index 9344394..cdbffd1 100644 --- a/RNNotifications/RNNotifications.m +++ b/RNNotifications/RNNotifications.m @@ -54,10 +54,13 @@ static NSString* username; UIApplicationState state = [UIApplication sharedApplication].applicationState; if (state == UIApplicationStateActive) { + // Notification received foreground [self didReceiveNotificationOnForegroundState:notification]; } else if (state == UIApplicationStateInactive) { + // Notification opened [self didNotificationOpen:notification]; } else { + // Notification received background [self didReceiveNotificationOnBackgroundState:notification]; } } @@ -135,10 +138,10 @@ static NSString* username; UILocalNotification* note = [[UILocalNotification alloc] init]; note.alertTitle = [alert objectForKey:@"title"]; note.alertBody = [alert objectForKey:@"body"]; - note.userInfo = managedAps; + note.userInfo = notification; note.soundName = [managedAps objectForKey:@"sound"]; + note.category = [managedAps objectForKey:@"category"]; - NSLog(@"Presenting local notification..."); [[UIApplication sharedApplication] presentLocalNotificationNow:note]; // Serialize it and store so we can delete it later @@ -157,12 +160,13 @@ static NSString* username; NSData* data = [[NSUserDefaults standardUserDefaults] objectForKey:notificationKey]; if (data) { UILocalNotification* notification = [NSKeyedUnarchiver unarchiveObjectWithData: data]; - NSLog(@"Remove local notification: %@", notificationKey); // delete the notification [[UIApplication sharedApplication] cancelLocalNotification:notification]; [[NSUserDefaults standardUserDefaults] removeObjectForKey:notificationKey]; + NSLog(@"Local notification removed: %@", notificationKey); + return; } } diff --git a/notification.ios.js b/notification.ios.js index dbc40ae..016d4e2 100644 --- a/notification.ios.js +++ b/notification.ios.js @@ -14,12 +14,11 @@ export default class IOSNotification { notification.aps["content-available"] === 1 && !notification.aps.alert && !notification.aps.sound && - !notification.aps.badge && notification.managedAps) { // managed notification this._alert = notification.managedAps.alert; this._sound = notification.managedAps.sound; - this._badge = notification.managedAps.badge; + this._badge = notification.aps.badge; this._category = notification.managedAps.category; this._type = "managed"; } else if ( diff --git a/test/notification.ios.spec.js b/test/notification.ios.spec.js index 660b729..0620108 100644 --- a/test/notification.ios.spec.js +++ b/test/notification.ios.spec.js @@ -74,7 +74,8 @@ describe("iOS Notification Object", () => { describe("for a managed iOS push notification (silent notification, with managedAps key and content-available = 1)", () => { let managedNativeNotification = { aps: { - "content-available": 1 + "content-available": 1, + badge: someBadgeCount }, managedAps: { action: "CREATE", @@ -83,7 +84,6 @@ describe("iOS Notification Object", () => { title: "some title", body: "some body" }, - badge: someBadgeCount, sound: someSound, category: someCategory }, -- 2.26.2