问题描述
我实际上是在使用https://allancritchie.net/posts/shiny-geofencing为我的Xamarin表单应用程序实现地理围栏,但是在“ GeofenceDelegate.cs”中并没有遇到断点。
谁能告诉我我的代码出了什么问题? 我正在android模拟器中进行测试。
using MyApp.Services.BackGroundJobs;
using Microsoft.Extensions.DependencyInjection;
using Shiny;
namespace MyApp
{
public class MyAppStart : ShinyStartup
{
public override void ConfigureServices(IServiceCollection builder)
{
builder.UseGeofencing<GeofenceDelegate>(true);
builder.UseNotifications(true);
}
}
}
using Shiny.Locations;
using Shiny.Notifications;
using System.Threading.Tasks;
namespace MyApp.Services.BackGroundJobs
{
public class GeofenceDelegate : IGeofenceDelegate
{
readonly Inotificationmanager notifications;
public GeofenceDelegate(Inotificationmanager notifications)
{
this.notifications = notifications;
}
public async Task OnStatusChanged(GeofenceState newStatus,GeofenceRegion region)
{
await this.notifications.Send(new Notification
{
Title = "Working",Message = "It is good to have you back " + region.Identifier
});
if (newStatus == GeofenceState.Entered)
{
await this.notifications.Send(new Notification
{
Title = "WELCOME!",Message = "It is good to have you back " + region.Identifier
});
}
else
{
await this.notifications.Send(new Notification
{
Title = "GOODBYE!",Message = "You will be missed at " + region.Identifier
});
}
}
}
}
MainActivity.cs
public override void OnRequestPermissionsResult(int requestCode,string[] permissions,Permission[] grantResults)
{
AndroidShinyHost.OnRequestPermissionsResult(requestCode,permissions,grantResults);
PermissionsImplementation.Current.OnRequestPermissionsResult(requestCode,grantResults);
}
MainApplication.cs
public override void OnCreate()
{
base.OnCreate();
RegisteractivityLifecycleCallbacks(this);
AndroidShinyHost.Init(this,new MyAppStart(),services => {
// register any platform specific stuff you need here
});
//A great place to initialize Xamarin.Insights and Dependency Services!
}
查看模型代码
private async void Checkgeofences()
{
// shiny doesn't usually manage your viewmodels,so we'll do this for Now
var geofences = ShinyHost.Resolve<IGeofenceManager>();
var notifications = ShinyHost.Resolve<Inotificationmanager>();
// this is really only required on iOS,but do it to be safe
var access = await notifications.RequestAccess();
if (access == Accessstate.Available)
{
await notifications.Send(new Notification
{
Title = "WELCOME!",Message = "Start GeofenceRegion"
});
await geofences.StartMonitoring(new GeofenceRegion(
"CN Tower - Toronto,Canada",new Position(23.7430,21.2363),distance.FromMeters(3)
)
{
NotifyOnEntry = true,NotifyOnExit = true,SingleUse = false
});
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)