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;
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;
}
}
......
......@@ -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 (
......
......@@ -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
},
......
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