Jelajahi Sumber

Fix handling notifications when application process has been killed #87

Sebastián Katzer 11 tahun lalu
induk
melakukan
f43aa60d49
2 mengubah file dengan 23 tambahan dan 2 penghapusan
  1. 2 1
      plugin.xml
  2. 21 1
      src/ios/APPLocalNotification.m

+ 2 - 1
plugin.xml

@@ -28,7 +28,8 @@
     <platform name="ios">
         <config-file target="config.xml" parent="/*">
             <feature name="LocalNotification">
-                <param name="ios-package" value="APPLocalNotification"/>
+                <param name="ios-package" value="APPLocalNotification" onload="true" />
+                <param name="onload" value="true" />
             </feature>
         </config-file>
 

+ 21 - 1
src/ios/APPLocalNotification.m

@@ -35,6 +35,8 @@
 - (UILocalNotification*) notificationWithProperties:(NSMutableDictionary*)options;
 // Ruft die JS-Callbacks auf, nachdem eine Notification eingegangen ist
 - (void) didReceiveLocalNotification:(NSNotification*)localNotification;
+// Ruft die JS-Callbacks auf, nachdem eine Notification eingegangen ist
+- (void) didFinishLaunchingWithOptions:(NSNotification*)notification;
 // Hilfsmethode gibt an, ob er String NULL oder Empty ist
 - (BOOL) strIsNullOrEmpty:(NSString*)str;
 // Fires the given event
@@ -300,12 +302,30 @@ NSString *const kAPP_LOCALNOTIFICATION = @"APP_LOCALNOTIFICATION";
     }
 }
 
+/**
+ * Ruft die JS-Callbacks auf, nachdem eine Notification eingegangen ist.
+ */
+- (void) didFinishLaunchingWithOptions:(NSNotification*)notification
+{
+    NSDictionary* launchOptions            = [notification userInfo];
+    UILocalNotification *localNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
+
+    if (localNotification)
+    {
+        [self didReceiveLocalNotification:notification];
+    }
+}
+
 /**
  * Registriert den Observer für LocalNotification Events.
  */
 - (void) pluginInitialize
 {
-    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveLocalNotification:) name:CDVLocalNotification object:nil];
+    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveLocalNotification:)
+                                                 name:CDVLocalNotification object:nil];
+
+    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didFinishLaunchingWithOptions:)
+                                                 name:UIApplicationDidFinishLaunchingNotification object:nil];
 }
 
 /**