cowbell / cordova-plugin-geofence

Geofencing plugin for cordova
Apache License 2.0
264 stars 318 forks source link

sending notifications in background /closed app #219

Open bigbossmaher opened 7 years ago

bigbossmaher commented 7 years ago

hi , thank you for this awesome plugin is there any way to make the plugin work when ap is closed or in background / when screen off also ?

seed880505 commented 7 years ago

@bigbossmaher For my experience, this plugin already works when app closed/in background/in screen off. iOS/Android will trigger your subscription when user has crossed your geo fences. If local notification doesn't work, you can try ionic push notification.

bigbossmaher commented 7 years ago

is it possible to send local notification using ionic push notification ? how ? because when i use cordova-plugin-geofence only the notification is shown only when the app is opened

seed880505 commented 7 years ago

Local/Push notification are different things. Push needs server side to send message. Local only concerns stuffs inside mobile. I suggest using local notification which has been already integrated in this plugin. It works in iOS, not tested for Android.

bigbossmaher commented 7 years ago

can you please tell me what is the plugin that i can use to make local notification , and please just tell me what is the code that i should put to send local notification thnaks

seed880505 commented 7 years ago

Have a look at this plugin https://github.com/katzer/cordova-plugin-local-notifications

Something like this:

window.geofence.onTransitionReceived = function (geofences) {
    geofences.forEach(function (geo) {
        console.log('Geofence transition detected', geo);

        // Your code here to use plugin
    cordova.plugins.notification.local.schedule({
        id: 1,
        title: "Geofence title",
        text: "Geofence text"
    });
    });
};
tsubik commented 7 years ago

@bigbossmaher @seed880505 javascript execution may be suspended when your application is the background, so the code above may not work. @bigbossmaher if you set notification object for geofence, you should get local notification. If you need to execute some custom action, https://github.com/cowbell/cordova-plugin-geofence#listening-for-geofence-transitions-in-native-code native code is the best choice.

bigbossmaher commented 7 years ago

hi , thank you for your answer. i'm satisfied about the current fonctionalities in the plugin . but it not working some times . how we can fix this ?

tsubik commented 7 years ago

Maybe you set too small radius? This plugin is a wrapper to native Geofence APIs which comes with all of their's limitations.

bigbossmaher commented 7 years ago

i'm developping an app that notify the user when he is in the parking , to help us to have an idea how much the parking is full ( 25% 50% 75% 100% ). so 50 m as a raduis is good ?

tsubik commented 7 years ago

Not sure, you have to look up for some answers on StackOverflow about native geofence API (android or iOS) minimum reliable radius.

bigbossmaher commented 7 years ago

why i should use native code ? is this plugin is not working in this situation ?

tsubik commented 7 years ago

This plugin uses native API, that's why read about limitations of those. You may also check https://github.com/transistorsoft plugins, maybe their solutions are more suitable for you.

bigbossmaher commented 7 years ago

just i want told you that the plugin is work very good when i use fake GPS app . but when i go to the place really i'm not getting a notification :(

tsubik commented 7 years ago

Try bigger radius and example applications. I have one always installed on my phone at works everytime, but never tried radius smaller than 200m.

bigbossmaher commented 7 years ago

thank you very much