Telerik-Verified-Plugins / Geofencing

Geofencing plugin for cordova, Telerik Platform compatible
Apache License 2.0
4 stars 2 forks source link

onNotificationClicked does not fire on cold start #6

Closed tabrindle closed 6 years ago

tabrindle commented 8 years ago

If the app is not inactive/running in background (app has been closed by iOS or force closed by the user) and a notification generated by this plugin is clicked, it will invoke the application but never call onNotificationClicked

I believe this is because didReceiveLocalNotification does not fire on cold start, and instead the plugin should also have an observer for didFinishLaunchingWithOptions to detect the app was invoked by a notification. Something like this:

    NSNotificationCenter.defaultCenter().addObserver(
        self,
        selector:  #selector(GeofencePlugin.didFinishLaunchingWithOptions(_:)),
        name: UIApplicationDidFinishLaunchingNotification,
        object: nil
    )

Then a function like this to call the didRecieveLocalNotification handler inside the Geofence class

    func didFinishLaunchingWithOptions(notification: NSNotification) {
        log("didFinishLaunchingWithOptions")

        let launchOptions = notification.userInfo!
        let localNotification = (launchOptions[UIApplicationLaunchOptionsLocalNotificationKey] as! BooleanType)
        if localNotification {
            self.didReceiveLocalNotification(notification)
        }
    }

The problem here is this observer never receives a didFinishLaunchingWithOptions event: Some of this is a bit over my head, but I believe the cordova-plugin-app-event plugin should handle rebroadcasting this, but it doesn't seem to work.

tabrindle commented 6 years ago

Used hacky workaround solar lights similar to Cordova notifications plugin. Closing.