我正在使用Plugin.Geofence i实现了它的接口,安装了它的依赖项,即.NETStandard 2.0
和Xamarin.GooglePlayServices.Location
。
当我运行System.InvalidCastException: Specified cast is not valid.
方法时,我得到了这个例外StartMonitoring
。
我在App()
构造函数中调用此方法。
public App ()
{
InitializeComponent();
MainPage = new NavigationPage(new MainPage());
CrossGeofence.Current.StartMonitoring(new GeofenceCircularRegion("MyRegion", 31.475085, 74.305833, 200)
{
//To get notified if user stays in region for at least 5 minutes
NotifyOnStay = true,
StayedInThresholdDuration = TimeSpan.FromMinutes(5)
});
}
尝试了一切,但无法解决这个问题
对于寻找解决方案的任何人,请在调用“CrossGeofence.Current”之前确保已请求并授予了正确的权限。如果没有,你会看到这个错误。