Commit 37492496 authored by Lidan Hifi's avatar Lidan Hifi

fix badge handling, added category to local notification

parent cfded35f
...@@ -54,10 +54,13 @@ static NSString* username; ...@@ -54,10 +54,13 @@ static NSString* username;
UIApplicationState state = [UIApplication sharedApplication].applicationState; UIApplicationState state = [UIApplication sharedApplication].applicationState;
if (state == UIApplicationStateActive) { if (state == UIApplicationStateActive) {
// Notification received foreground
[self didReceiveNotificationOnForegroundState:notification]; [self didReceiveNotificationOnForegroundState:notification];
} else if (state == UIApplicationStateInactive) { } else if (state == UIApplicationStateInactive) {
// Notification opened
[self didNotificationOpen:notification]; [self didNotificationOpen:notification];
} else { } else {
// Notification received background
[self didReceiveNotificationOnBackgroundState:notification]; [self didReceiveNotificationOnBackgroundState:notification];
} }
} }
...@@ -135,10 +138,10 @@ static NSString* username; ...@@ -135,10 +138,10 @@ static NSString* username;
UILocalNotification* note = [[UILocalNotification alloc] init]; UILocalNotification* note = [[UILocalNotification alloc] init];
note.alertTitle = [alert objectForKey:@"title"]; note.alertTitle = [alert objectForKey:@"title"];
note.alertBody = [alert objectForKey:@"body"]; note.alertBody = [alert objectForKey:@"body"];
note.userInfo = managedAps; note.userInfo = notification;
note.soundName = [managedAps objectForKey:@"sound"]; note.soundName = [managedAps objectForKey:@"sound"];
note.category = [managedAps objectForKey:@"category"];
NSLog(@"Presenting local notification...");
[[UIApplication sharedApplication] presentLocalNotificationNow:note]; [[UIApplication sharedApplication] presentLocalNotificationNow:note];
// Serialize it and store so we can delete it later // Serialize it and store so we can delete it later
...@@ -157,12 +160,13 @@ static NSString* username; ...@@ -157,12 +160,13 @@ static NSString* username;
NSData* data = [[NSUserDefaults standardUserDefaults] objectForKey:notificationKey]; NSData* data = [[NSUserDefaults standardUserDefaults] objectForKey:notificationKey];
if (data) { if (data) {
UILocalNotification* notification = [NSKeyedUnarchiver unarchiveObjectWithData: data]; UILocalNotification* notification = [NSKeyedUnarchiver unarchiveObjectWithData: data];
NSLog(@"Remove local notification: %@", notificationKey);
// delete the notification // delete the notification
[[UIApplication sharedApplication] cancelLocalNotification:notification]; [[UIApplication sharedApplication] cancelLocalNotification:notification];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:notificationKey]; [[NSUserDefaults standardUserDefaults] removeObjectForKey:notificationKey];
NSLog(@"Local notification removed: %@", notificationKey);
return; return;
} }
} }
......
...@@ -14,12 +14,11 @@ export default class IOSNotification { ...@@ -14,12 +14,11 @@ export default class IOSNotification {
notification.aps["content-available"] === 1 && notification.aps["content-available"] === 1 &&
!notification.aps.alert && !notification.aps.alert &&
!notification.aps.sound && !notification.aps.sound &&
!notification.aps.badge &&
notification.managedAps) { notification.managedAps) {
// managed notification // managed notification
this._alert = notification.managedAps.alert; this._alert = notification.managedAps.alert;
this._sound = notification.managedAps.sound; this._sound = notification.managedAps.sound;
this._badge = notification.managedAps.badge; this._badge = notification.aps.badge;
this._category = notification.managedAps.category; this._category = notification.managedAps.category;
this._type = "managed"; this._type = "managed";
} else if ( } else if (
......
...@@ -74,7 +74,8 @@ describe("iOS Notification Object", () => { ...@@ -74,7 +74,8 @@ describe("iOS Notification Object", () => {
describe("for a managed iOS push notification (silent notification, with managedAps key and content-available = 1)", () => { describe("for a managed iOS push notification (silent notification, with managedAps key and content-available = 1)", () => {
let managedNativeNotification = { let managedNativeNotification = {
aps: { aps: {
"content-available": 1 "content-available": 1,
badge: someBadgeCount
}, },
managedAps: { managedAps: {
action: "CREATE", action: "CREATE",
...@@ -83,7 +84,6 @@ describe("iOS Notification Object", () => { ...@@ -83,7 +84,6 @@ describe("iOS Notification Object", () => {
title: "some title", title: "some title",
body: "some body" body: "some body"
}, },
badge: someBadgeCount,
sound: someSound, sound: someSound,
category: someCategory category: someCategory
}, },
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment