[英]Xamarin CrossGeofence Transitions
我在这里下载并安装了xamarin的CrossGeofence插件: https : //github.com/domaven/xamarin-plugins/tree/master/Geofence
使用此处找到的示例作为准则: https : //github.com/domaven/xamarin-plugins/tree/master/Samples/Geofence
而且我一直在使用USB调试在我的实体电话LGE LG-D852(Android 6.0-API 23)上对其进行测试。
我的CrossGeofenceListener类已实现,例如:
public class CrossGeofenceListener : IGeofenceListener
{
//TODO: figure out what to do with this one.
public void OnAppStarted()
{
//throw new NotImplementedException();
}
//copied from geofence sample
public void OnError(string error)
{
Debug.WriteLine(string.Format("{0} - {1}: {2}", CrossGeofence.Id, "Error", error));
}
//TODO: figure out what needs to be done when the location changes.
public void OnLocationChanged(GeofenceLocation location)
{
//throw new NotImplementedException();
}
//copied from geofence sample
public void OnMonitoringStarted(string region)
{
Debug.WriteLine(string.Format("{0} - {1}: {2}", CrossGeofence.Id, "Monitoring in region", region));
}
//copied from geofence sample
public void OnMonitoringStopped()
{
Debug.WriteLine(string.Format("{0} - {1}", CrossGeofence.Id, "Monitoring stopped for all regions"));
}
//copied from geofence sample
public void OnMonitoringStopped(string identifier)
{
Debug.WriteLine(string.Format("{0} - {1}: {2}", CrossGeofence.Id, "Monitoring stopped in region", identifier));
}
//copied from geofence sample
public void OnRegionStateChanged(GeofenceResult result)
{
Debug.WriteLine(string.Format("{0} - {1}", CrossGeofence.Id, result.ToString()));
}
}
并且我已经创建并开始监视围栏,例如:
foreach (var facility in Facilities)
{
CrossGeofence.Current.StartMonitoring(new GeofenceCircularRegion(facility.Name, facility.Latitude, facility.Longitude, 2000)
{
NotifyOnStay = true,
NotifyOnEntry = true,
NotifyOnExit = true,
ShowNotification = true,
ShowEntryNotification = false,
ShowExitNotification = false,
ShowStayNotification = true,
NotificationStayMessage = "stay message!",
NotificationEntryMessage = "entry message!",
NotificationExitMessage = "exit message!",
StayedInThresholdDuration = TimeSpan.FromSeconds(1),
});
}
有了以上所述,我只会弹出输入的地理围栏通知。 我没有收到退出通知,而是停留了过渡通知。 关于如何使停留和退出转换触发的任何建议?
在与其他应用程序欺骗GPS坐标后,它已开始正确报告停留和退出通知。 我唯一的假设是,由于gps坐标的变化不够大,之前没有任何工作。
根据以下代码片段(在您的帖子中描述):
ShowEntryNotification = false,
ShowExitNotification = false,
ShowStayNotification = true,
您应该收到“停留”通知,但没有进入/退出通知,为了接收其中的三个通知,请将“ Show ... Notification”设置为true。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.