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
19 changes: 16 additions & 3 deletions src/cordova/android/local/src/LocalNotificationsReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.app.Notification;
import android.app.NotificationManager;
import android.app.NotificationChannel;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
Expand Down Expand Up @@ -57,7 +58,20 @@ public void onReceive(Context context, Intent intent) {
String contentBody = data.contentBody == null ? "" : data.contentBody;

Notification notification;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {

/* Create or update. */
NotificationChannel channel = new NotificationChannel(
"my_channel_01",
"Game Notifications",
NotificationManager.IMPORTANCE_DEFAULT
);
notificationManager.createNotificationChannel(channel);
}

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
int defaults = android.app.Notification.DEFAULT_LIGHTS | android.app.Notification.DEFAULT_VIBRATE;
if (data.soundEnabled) {
defaults |= android.app.Notification.DEFAULT_SOUND;
Expand All @@ -70,7 +84,6 @@ public void onReceive(Context context, Intent intent) {
.setAutoCancel(true)
.setContentIntent(contentIntent)
.build();

} else {
int defaults = android.app.Notification.DEFAULT_LIGHTS | android.app.Notification.DEFAULT_VIBRATE;
if (data.soundEnabled) {
Expand All @@ -83,10 +96,10 @@ public void onReceive(Context context, Intent intent) {
.setDefaults(defaults)
.setAutoCancel(true)
.setContentIntent(contentIntent)
.setChannelId("my_channel_01")
.build();
}

NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(data.cocoonId, notification);
}

Expand Down
2 changes: 1 addition & 1 deletion src/cordova/common/src/android/libs/notifications.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
dependencies {
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:support-compat:27.1.1'
}
2 changes: 1 addition & 1 deletion src/cordova/common/www/cocoon_notifications.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions src/cordova/ios/local/src/ios/LDNotificationLocalPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ - (void)pluginInitialize
[super pluginInitialize];
_scheduledNotifications = [[NSMutableDictionary alloc] init];

// load scheduled notifications
NSArray<UILocalNotification *> *scheduled = [UIApplication sharedApplication].scheduledLocalNotifications;
for (UILocalNotification *notification in scheduled) {
NSMutableDictionary * userInfo = [NSMutableDictionary dictionaryWithDictionary: notification.userInfo ?: @{}];
NSString *identifier = [userInfo objectForKey:COCOON_NOTIFICATION_ID];
// place it back into the scheduledNotifications dict
if (identifier && [identifier isKindOfClass:[NSString class]]) {
[_scheduledNotifications setObject:notification forKey:identifier];
}
}

if (!processedLaunchNotifications) {
NSDictionary * launchOptions = [CDVAppDelegate launchOptions];
if (launchOptions) {
Expand Down
2 changes: 1 addition & 1 deletion src/js/cocoon_notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
function NotificationService(serviceName) {
this.serviceName = serviceName;
this.signal = new Cocoon.Signal();
this.idIndex = 0;
this.idIndex = Date.now();
/**
* Allows to listen to events when the application receives a notification.
* @memberOf Cocoon.Notification
Expand Down