CrossGeeks / GeofencePlugin

Geofence Plugin for Xamarin iOS and Android
MIT License
48 stars 22 forks source link

OnRegionStateChanged - never get executed #5

Open kberawala opened 5 years ago

kberawala commented 5 years ago

OnRegionStateChanged never gets executed ? and OnLocationChanged get called repeatedly.

and any plans for sample ?

willsam100 commented 5 years ago

I had the same problem and found that it only occurred when I was targetting Android 8.0 or higher. When I rolled the target back to Android 7.0 then OnRegionStateChanged started working again (even running on an Android 8 device).

This is a short-term fix though, as Google is not accepting new apps that target Android 7.0 and current apps have until the end of the year (2018) to update.

manzha commented 5 years ago

I had the same problem and found that it only occurred when I was targetting Android 8.0 or higher. When I rolled the target back to Android 7.0 then OnRegionStateChanged started working again (even running on an Android 8 device).

This is a short-term fix though, as Google is not accepting new apps that target Android 7.0 and current apps have until the end of the year (2018) to update.

I tried this fix but it only results in OnLocationChanged being called repeatedly and OnRegionStateChanged only being called once at the very start of the app. I can't make it work :(

Isn't there any project sample?

HeroXx commented 5 years ago

I am also having this issue, any help?

manzha commented 5 years ago

I am not sure if the problem was because I was debugging using a physical device and an application for mocking locations, as for android API 26, this technique (mocking locations in device) is not working correctly with some apps (it constantly jumped from original location to mock location). I became aware of this days laters (too late as I was using a different approach to my problem).

So my advice would be to try debug it while walking in real time, and not using mockup locations (at least for android, not sure ios).

patkozlowski commented 5 years ago

Any ETA on fixing this for Android 8.0 and above? I’m noticing this same exact behavior. I have an app in production that heavily uses this.

patkozlowski commented 5 years ago

I had to modify the API to get this to work with my specific use case. This does work for Android 8 and above, but I had to start the service as a foreground service, or else you will get some illegal state exception due to android 8 background service limitations, maybe that could be implemented into the project in the future. I've also noticed that builder.SetInitialTrigger(GeofencingRequest.InitialTriggerDwell) worked for me as I want to be notified when starting the geofence, after the dwelling time for the user to be notified. You can set based upon your specific use case to use the defaulted InitialTriggerEnter or even builder.SetInitialTrigger(GeofencingRequest.InitialTriggerDwell | GeofeningRequest.InitialTriggerEnter). I use on a real device and test using an app called "Fake GPS" which works pretty well of mocking and changing locations for testing.

For iOS you can follow this youtube video for spoofing your gps on the real device. The workflow I use is to have the app already loaded on your phone (you can't debug though, as you will be running the blank "gps spoofer app" in xcode). Change the coordinates in the black app, and see the gps changes reflected in the app using the geofencing api.