Geofence Plugin - can geofence interact with app logic?

Xamarin forms app, running on iOS and Android, using Geofence Plugin.

I have implemented a CrossGeofenceListener, which basically gives the user a notification when he is entering/leaving an area. What I would like to do, is to interact with the app (a ViewModel) to behave more intelligently. A simplified example:

The app allows the user to be checked in to certain locations, one at a time.
1.When entering a location and not already checked in: Notify
2.When entering a location and already checked in: Do nothing
3.When leaving a location while checked in: Notify
4.When leaving a location and not checked in: Do nothing

This would require some sort of shared state, either by injecting my viewmodel or some other object to the CrossGeofenceListener, or some other strategy. Since the app itself is likely to be backgrounded when entering/leaving a location, I wonder if this is even possible, and if so, what are the best practices around it. I guess there can be differences between Android/iOS as well, since Android is implementing a separate backgrounding service, while iOS seems to be able to handle it by itself.

Would I be able to inject the whole ViewModel to the CrossGeoFenceListener and read/manipulate values just as I want?

The next step is of course to actually try it out, but wanted to ask first in case any of you guys already know, since it is a big hassle to test these things, since it basically requires me to walk in and out of the defined area.

Answers

  • ThorvaldBoeThorvaldBoe NOMember ✭✭

    I will try it out, but I don't have high hopes. After doing some more testing on the basic functions, I am a bit disappointed, since the plugin seems to have several issues on iOS:

    -Even if setting 'Persistent = true', it seems like I am not getting notifications after a certain period of time. Don't know exactly how long, but it is almost as the app is falling asleep after a certain period of time
    -I don't get notifications if the app is closed, even if the intellisense says I should
    -On iOS, (when it is working) I always get two notifications when leaving a region

    On Android, these things seem to work ok.

    I wonder if anyone is actually using the Geofence plugin in production and can confirm that the plugin is working on iOS? If so, I am most likely doing something wrong. Otherwise, the plugin has severe flaws and it not usable except for demo purposes. It would be a shame if I would have to implement iOS support myself because of a sloppy plugin implementation.

    Sorry for wandering off-topic here, but I guess there is little point solving the advanced use case if the basic stuff is not working.

  • ThorvaldBoeThorvaldBoe NOMember ✭✭

    Minor update: Seems like the basic use case is working now. I don't know why is was not working before. It might have been a deployment issue. Although I am sure I deployed the new version with 'Persistent = true' (because I also made visual changes that I observed was there), I suspect the monitored regions were somehow not updated. But after deploying the app once more, the notifications started to work, even when the app was closed. So that's a good thing.

    I still get notifications twice when leaving a region though, but that's a minor detail.

    So now I am back on the advanced use case, to see if I can actively act upon the geofence events in my app. I did some very basic testing, where I just injected my viewmodel to the CrossGeofenceListener and had it execute a command when a region state changed. That sort of worked, but I suspect the command was actually executed when I opened the app, not necessarily when the region state change occurred, at least I need to test more to verify what happens. Will post more later.

Sign In or Register to comment.