cowbell / cordova-plugin-geofence

Geofencing plugin for cordova
Apache License 2.0
265 stars 316 forks source link

Implementing "UIApplicationDidFinishLaunchingNotification" #124

Open johnrobertcobbold opened 8 years ago

johnrobertcobbold commented 8 years ago

I have been trying to implement catching "UIApplicationDidFinishLaunchingNotification" to this plugin but have not been able to achieve it with my limited Swift skills...

I am able to implement a javascript callback to a geofence transition on iOS when the app : (1) is in the foreground, (2) is alive in the background (3) was killed (in which case iOS just opens up the app again before executing my JS callback.

However, in case (3), the app proceeds to load as usual, therefore synchronising content from the cloud that is not necessary as the app is launched in the background and invisible to the user. In order to avoid this, it is my understanding that we need to catch 'UIApplicationDidFinishLaunchingNotification'.

What I thought might work was adding the following inside the pluginInitialize function :

        NSNotificationCenter.defaultCenter().addObserver(
            self,
            selector: "didFinishLaunching:",
            name: "UIApplicationDidFinishLaunchingNotification",
            object: nil
        )

and the following function (which I have not finished since it is not working for now..) :

    func didFinishLaunching (notification: NSNotification) {
        log("didFinishLaunching")
        if let userInfo = notification.userInfo as? Dictionary<String,String> {
            if let s = userInfo["UIApplicationLaunchOptionsLocationKey"] {
                log("UIApplicationLaunchOptionsLocationKey")
            }
        }
    } 

didFinishLaunching is not even getting called as didFinishLaunching never appears in my logs. I am however 100% sure that my app is launching after I killed it due to a geofence event as I can see the app being re-oponed and my callback called in the logs.

Perhaps someone could help implement this ? I was hoping to add a function for example like window.geofence.hasUIApplicationLaunchOptionsLocationKey() which would return a boolean :) Sounds like a good new feature for this plugin.

Wade-BuildOtto commented 7 years ago

+1

without the didFinishLaunching I can't seem to get the updates to process in the background on region transition change.

something like: