Browse Source

Fix trigger/click issue with repeating notifications on iOS

Sebastián Katzer 11 years ago
parent
commit
a729de7790

+ 1 - 1
src/ios/APPLocalNotificationOptions.m

@@ -82,7 +82,7 @@
 - (BOOL) autoCancel
 {
     if (IsAtLeastiOSVersion(@"8.0")){
-        return YES;
+        return self.repeatInterval == NSCalendarUnitEra;
     } else {
         return [[dict objectForKey:@"autoCancel"] boolValue];
     }

+ 1 - 1
src/ios/UILocalNotification+APPLocalNotification.h

@@ -28,7 +28,7 @@
 // The options provided by the plug-in
 - (APPLocalNotificationOptions*) options;
 // Timeinterval since fire date
-- (NSTimeInterval) timeIntervalSinceFireDate;
+- (double) timeIntervalSinceFireDate;
 // If the fire date was in the past
 - (BOOL) wasInThePast;
 // If the notification was already triggered

+ 31 - 2
src/ios/UILocalNotification+APPLocalNotification.m

@@ -95,15 +95,44 @@ static char optionsKey;
                              options, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
 }
 
+/**
+ * The repeating interval in seconds.
+ */
+- (int) repeatIntervalInSeconds
+{
+    switch (self.repeatInterval) {
+        case NSCalendarUnitMinute:
+            return 60;
+
+        case NSCalendarUnitHour:
+            return 60000;
+
+        case NSCalendarUnitDay:
+        case NSCalendarUnitWeekOfYear:
+        case NSCalendarUnitMonth:
+        case NSCalendarUnitYear:
+            return 86400;
+
+        default:
+            return 1;
+    }
+}
+
 /**
  * Timeinterval since fire date.
  */
-- (NSTimeInterval) timeIntervalSinceFireDate
+- (double) timeIntervalSinceFireDate
 {
     NSDate* now      = [NSDate date];
     NSDate* fireDate = self.options.fireDate;
 
-    return [now timeIntervalSinceDate:fireDate];
+    int timespan     = [now timeIntervalSinceDate:fireDate];
+
+    if (self.repeatInterval != NSCalendarUnitEra) {
+        timespan = timespan % [self repeatIntervalInSeconds];
+    }
+
+    return timespan;
 }
 
 /**