Commit 30da4b36 by Sebastián Katzer Committed by GitHub

Merge pull request #1093 from spk0611/master

iOS 10 (some hot fixes)
parents 366557fd 9ad32cf2
...@@ -37,6 +37,7 @@ import org.json.JSONObject; ...@@ -37,6 +37,7 @@ import org.json.JSONObject;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.lang.Exception;
import de.appplant.cordova.plugin.notification.Manager; import de.appplant.cordova.plugin.notification.Manager;
import de.appplant.cordova.plugin.notification.Notification; import de.appplant.cordova.plugin.notification.Notification;
...@@ -213,10 +214,18 @@ public class LocalNotification extends CordovaPlugin { ...@@ -213,10 +214,18 @@ public class LocalNotification extends CordovaPlugin {
for (int i = 0; i < notifications.length(); i++) { for (int i = 0; i < notifications.length(); i++) {
JSONObject options = notifications.optJSONObject(i); JSONObject options = notifications.optJSONObject(i);
Notification notification = try {
getNotificationMgr().schedule(options, TriggerReceiver.class); Notification notification =
getNotificationMgr().schedule(options, TriggerReceiver.class);
fireEvent("schedule", notification); fireEvent("schedule", notification);
}
catch(Exception generic) {
//silently ignore the exception
//on some samsung devices there is a known bug where a 500 alarms limit can crash the app
//http://developer.samsung.com/forum/board/thread/view.do?boardName=General&messageId=280286&listLines=15&startId=zzzzz%7E&searchSubId=0000000001
}
} }
} }
......
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
#import "UIApplication+APPLocalNotification.h" #import "UIApplication+APPLocalNotification.h"
#import "UILocalNotification+APPLocalNotification.h" #import "UILocalNotification+APPLocalNotification.h"
@import UserNotifications;
@interface APPLocalNotification () @interface APPLocalNotification ()
// Retrieves the application state // Retrieves the application state
...@@ -76,6 +78,8 @@ ...@@ -76,6 +78,8 @@
notification = [[UILocalNotification alloc] notification = [[UILocalNotification alloc]
initWithOptions:options]; initWithOptions:options];
notification.timeZone = [NSTimeZone defaultTimeZone];
notification.repeatInterval = 0;
[self scheduleLocalNotification:[notification copy]]; [self scheduleLocalNotification:[notification copy]];
[self fireEvent:@"schedule" notification:notification]; [self fireEvent:@"schedule" notification:notification];
...@@ -691,6 +695,47 @@ ...@@ -691,6 +695,47 @@
*/ */
- (void) fireEvent:(NSString*)event notification:(UILocalNotification*)notification - (void) fireEvent:(NSString*)event notification:(UILocalNotification*)notification
{ {
if (IsAtLeastiOSVersion(@"10.0")) {
UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
content.title = [NSString localizedUserNotificationStringForKey:notification.alertTitle arguments:nil];
content.body = [NSString localizedUserNotificationStringForKey:notification.alertBody
arguments:nil];
content.sound = [UNNotificationSound defaultSound];
NSDate *fireDate = notification.fireDate;
if(fireDate==nil) {
fireDate = [NSDate date];
}
NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
// Extract all date components into dateComponents
NSDateComponents *dateComponents = [gregorianCalendar components:NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit
| NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit
fromDate:fireDate];
[dateComponents setTimeZone:[NSTimeZone defaultTimeZone]];
/// 4. update application icon badge number
//content.badge = @([[UIApplication sharedApplication] applicationIconBadgeNumber] + 1);
// Deliver the notification at the fire date.
UNCalendarNotificationTrigger *trigger = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:dateComponents repeats:NO];
NSString *identifier = @"DefaultNotificationIdentifier";
if(notification.userInfo!=nil && [notification.userInfo objectForKey:@"id"]!=nil) {
identifier = [notification.userInfo objectForKey:@"id"];
}
UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:identifier content:content trigger:trigger];
/// 3. schedule localNotification
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
[center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
if (!error) {
NSLog(@"add NotificationRequest succeeded!");
}
}];
}
NSString* js; NSString* js;
NSString* params = [NSString stringWithFormat: NSString* params = [NSString stringWithFormat:
@"\"%@\"", self.applicationState]; @"\"%@\"", self.applicationState];
......
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