Hi guys
Just released a plugin that supports geofence monitoring for iOS and Android Platform. Windows support coming soon. Try it and let me know if helps any one. Also have a list of TODOs if anyone would like to collaborate in this project that would be awesome!
Geofence Plugin Github repository
Thanks.
Posts
@RendyDelRosario well done, good work.
Thanks @AlessandroCaliaro. Tested it already?
I will upload a sample app maybe tomorrow. To be easier to see how it works.
Sample here: https://github.com/domaven/xamarin-plugins/tree/master/Samples/Geofence
Geofence Sample Android APK
Hi,
I have to fire local notification from based on geofencing result . It worked when app in online and bagrounded but it is not working when the app is offline. Please advice is it possible using this Nugget ? Please share some samples incase it is possible.
Regards
Mohanlal
Geofence NuGet PCL : https://www.nuget.org/packages/Xam.Plugin.Geofence/
Sample here: https://github.com/domaven/xamarin-plugins/tree/master/Samples/Geofence
@RendyDelRosario is there any method on your plugin to get the current location?
I need to get the current location of the device before starting with the monitoring, can this current location be retrieved with your plugin?
There's a property you can use:
GeofenceLocation LastKnownLocation { get; }
CrossGeofence.Current.LastKnownLocation;
@RendyDelRosario Hello again. I'm having issues with the plugin I start monitoring a region I get the OnMonitoringStarted event and OnError is not fired so I assumed is monitoring. However I never get OnRegionStateChanged event
Any ideas?
Ok the OnStay is the only event that is not firing now.
@AlejandroForonda did you set NotifyOnStay to true? When started monitoring the region?
@RendyDelRosario Yes. Is set to true
Are you testing on Android or iOS?
Hello @RendyDelRosario ! Thanks for this nice plugin!
I'm having an issue on iOS devices though.
In my AppDelegate I call:
CrossGeofence.Initialize<GeofenceListener>();
Then, in the OnStart override of my Forms application, I call:
On Android and an iOS 9.1 simulator, this works flawlessly, and I get notified when entering or leaving my region
On a real iOS 9.1 device though, I get an exception while fetching CrossGeofence.Current:
Do you have any idea how I could fix this?
Best regards,
David
Hi
@DavidCatteuw Are you still having the issue?
Do you have a sample repo that reproduce this situation to test?
Hello Rendy,
The iOS version of my prototype has been put on hold for the moment, so I can't really dedicate any time to it right now.
I'll get back to you when this gets started up again.
Thanks again for the nice library!
Best regards,
David
I've tested this out with iOS (will be testing android in the near future), it works very well for me. Nice job OP!
Hi, Just added the plug in to my app - Xamain.Android.
I get this exception when trying to add geofence:
System.TypeLoadException: Could not load type 'Android.Gms.Common.GoogleApiAvailability' from assembly 'Xamarin.GooglePlayServices.Basement, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. 01-29 09:32:18.249 I/mono-stdout(27865): System.TypeLoadException: Could not load type 'Android.Gms.Common.GoogleApiAvailability' from assembly 'Xamarin.GooglePlayServices.Basement, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. 01-29 09:32:18.250 I/mono-stdout(27865): at Geofence.Plugin.GeofenceImplementation.IsLocationEnabled (System.Action
1 returnAction) [0x0000d] in C:\Users\rendy\Maven\xamarin-plugins\Geofence\Geofence\Geofence.Plugin.Android\GeofenceImplementation.cs:133at Geofence.Plugin.GeofenceImplementation.IsLocationEnabled (System.Action
1 returnAction) [0x0000d] in C:\Users\rendy\Maven\xamarin-plugins\Geofence\Geofence\Geofence.Plugin.Android\GeofenceImplementation.cs:133 at Geofence.Plugin.GeofenceImplementation..ctor () [0x00021] in C:\Users\rendy\Maven\xamarin-plugins\Geofence\Geofence\Geofence.Plugin.Android\GeofenceImplementation.cs:112 01-29 09:32:18.250 I/mono-stdout(27865): at Geofence.Plugin.GeofenceImplementation..ctor () [0x00021] in C:\Users\rendy\Maven\xamarin-plugins\Geofence\Geofence\Geofence.Plugin.Android\GeofenceImplementation.cs:112 01-29 09:32:18.250 I/mono-stdout(27865): at Geofence.Plugin.CrossGeofence.CreateGeofence () [0x00000] in C:\Users\rendy\Maven\xamarin-plugins\Geofence\Geofence\Geofence.Plugin\CrossGeofence.cs:128 01-29 09:32:18.251 I/mono-stdout(27865): at Geofence.Plugin.CrossGeofence+<>c.<.cctor>b__55_0 () [0x00000] in C:\Users\rendy\Maven\xamarin-plugins\Geofence\Geofence\Geofence.Plugin\CrossGeofence.cs:14 at Geofence.Plugin.CrossGeofence.CreateGeofence () [0x00000] in C:\Users\rendy\Maven\xamarin-plugins\Geofence\Geofence\Geofence.Plugin\CrossGeofence.cs:128 at Geofence.Plugin.CrossGeofence+<>c.<.cctor>b__55_0 () [0x00000] in C:\Users\rendy\Maven\xamarin-plugins\Geofence\Geofence\Geofence.Plugin\CrossGeofence.cs:14
My package config:
<package id="Xam.Plugin.Geofence" version="1.0.9" targetFramework="monoandroid44" developmentDependency="true" /> <package id="Xamarin.Android.Support.v4" version="23.1.1.0" targetFramework="monoandroid44" /> <package id="Xamarin.Android.Support.v7.AppCompat" version="22.2.0.0" targetFramework="monoandroid44" /> <package id="Xamarin.Android.Support.v7.CardView" version="22.1.1.1" targetFramework="monoandroid44" /> <package id="Xamarin.GooglePlayServices.Auth" version="29.0.0-beta1" targetFramework="monoandroid44" /> <package id="Xamarin.GooglePlayServices.Base" version="29.0.0-beta1" targetFramework="monoandroid44" /> <package id="Xamarin.GooglePlayServices.Basement" version="29.0.0-beta1" targetFramework="monoandroid44" /> <package id="Xamarin.GooglePlayServices.Gcm" version="29.0.0-beta1" targetFramework="monoandroid44" /> <package id="Xamarin.GooglePlayServices.Location" version="29.0.0-beta1" targetFramework="monoandroid44" /> <package id="Xamarin.GooglePlayServices.Maps" version="29.0.0-beta1" targetFramework="monoandroid44" /> <package id="Xamarin.GooglePlayServices.Measurement" version="29.0.0-beta1" targetFramework="monoandroid44" /> <package id="Xamarin.GooglePlayServices.Plus" version="29.0.0-beta1" targetFramework="monoandroid44" />
Packages issue as it turns out I'm using 29.0.0-beta1 and plugin uses 27.0.0.0 currently. Downgraded to 27 and all worked fine.
Right @MilenPavlov.0879 We are not supporting 29 beta yet, just stable versions
@RendyDelRosario btw works just fine with 29 beta too
Hi @RendyDelRosario, thanks for doing this!
Does this Nuget also support updates even when the app is terminated? As in a background service that will get notified when there is a Geofence change?
@SpencerSmith yes
Hi,
i cannot make geofence work when app is closed. i have created service and started but i don't receive notification for geofence
Hi @RendyDelRosario, thanks for your plugin.
I encounter one problem when using the latest version. That is the Exit event will be invoked twice. It means that Enter the region occur one time, however the Exited the region occur 2 times. I have try the sample which use the 1.0.4 without this problem. However I update the plugin to 1.1.1, the problem occurred again in the Sample. I think it is a bug maybe.
Test Case: Using iOS Emulator
@RendyDelRosario
Could I ask one question for this Plugin?
I have tried the sample code, it worked and I found even I close the app (swipe it out after double click home button),it still can monitor the region change.
However, I want to implement this function too. I have try it in my code, I found except I put the StartMonitoring in the OnAppStart function, the monitor can not valid after I close the app. I compare the code with the sample, and I cannot find any different except the sample code use Xamarin.FormMaps. Is this the reason why the sample code can run even the app close?
If not Could you give me some suggestion how to enable the region monitor running background after the app close?
Quick update this problem:
I just add a single debug line in the AppDelegate.cs, the background task monitor worked! Strange
Update the problem and solution when I use this plugin
the sample code is based on 1.0.4, as far as I know that I encountered twice exited notification issue by version 1.1.1. So I choose the 1.0.4.
The old version is based on deprecated Google play service, ( I think 1.0.6 update it to new package which include 4 packages). so care about the package reference.
After last update Xamarin Forms 2.2.0.31 that finally fixed the Xamarin.Android.Support update issue, I'm now getting an error from this plugin I have no idea how to fix.
Error: Error executing task LinkAssemblies: error XA2006: Reference to metadata item 'Android.Gms.Common.GoogleApiAvailability Android.Gms.Common.GoogleApiAvailability::get_Instance()' (defined in 'Geofence.Plugin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null') from 'Geofence.Plugin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' could not be resolved.
Any help is appreciated.
Figured it out, I removed all the GooglePlayServices and Xam.Plugin.Geofence then re-installed Geofence and let it get the dependancies. A few of the GooglePlayServices were .1 version too high.
I'm getting the same error for RELEASE and PRODUCTION builds:
Error: Error executing task LinkAssemblies: error XA2006: Reference to metadata item 'Android.Gms.Common.GoogleApiAvailability Android.Gms.Common.GoogleApiAvailability::get_Instance()' (defined in 'Geofence.Plugin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null') from 'Geofence.Plugin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' could not be resolved.
Tried removing the Google play services packages and geofence, and re-adding geofence nuget package. But still seeing the error.
Any ideas?
thanks,
Dennis
@RendyDelRosario I am not getting any error.
Able to test successfully in IOS, but in android not getting notified on any event event though tried with highest accuracy.
I have conducted test using AVD & actual device also.
Can you suggest on this, am I missing anything?
I having the same problem as @Dennis.Stringify
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets: Error: Error executing task LinkAssemblies: error XA2006: Reference to metadata item 'Android.Gms.Common.GoogleApiAvailability Android.Gms.Common.GoogleApiAvailability::get_Instance()' (defined in 'Geofence.Plugin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null') from 'Geofence.Plugin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' could not be resolved.
I was only able to deploy a release version only with "Don't Link Assemblies" in the Linker settings. But the package gets too big.
Any suggestion @RendyDelRosario ?
Hi , How can I Add routes and traffic to this sample?
I tested the sample and
it surprises me that it does not crash with the data/4G turned off. that's very good and stable.
Thanks for your awesome plugin, great job and it definitely is a time saver!
Unfortunately, the current Xamarin.Forms.Maps references Play Services 29.0.0.1, which mismatches with the version referenced by the Geofence plugin (which is 27.0.0.0...).
That creates problems as reported by @jzeferino or, in my case, something like:
You might want to upgrade the plugin to 29.0.0.1 to fix this...
@CyrilCathala how did you managed to bypass that error? downgrading to 27.0.0.0? I donwgrade it but still the same error.
I've downloaded the source code, changed the reference to the Play Services (to target 29.0.0.1), got the dll and referenced then directly. Just make sure you clean you bin + obj folders before you build your project, otherwise it works perfectly!
Why would this be necessary, or even address the issue? The plugin requires 27.0.0.0 or greater .
It requires 27.0.0.0 but won't work if you update to 29.0.0.0.
@CyrilCathala i don't want to have to reference the .dll. Its kinda bad because if they update the library i will need to refactor the dependency.
I will try to make a PR for the repository.
Yes I know, I don't like it either but I couldn't wait, I have to ship my app pretty soon
I hope it'll be temporary (thanks to your PR maybe
).