Xamarin表单-在地理围栏中不会触发带有闪亮的地理围栏

问题描述 投票:0回答:1

我已经创建了xamarin表单应用程序,并且其中一项要求如下:用户应该能够按下按钮并创建地理围栏。创建地理围栏后,应用程序会不断检查用户是否在地理围栏中。没错,移动应用程序应显示通知sayinf:您已输入地理围栏。

我使用Shiny来实现基于本教程的功能:“ https://allancritchie.net/posts/shiny-geofencing”。

但是问题是它什么也没做。我已将地理围栏设置为距我的房子50米,并且将检查半径设置为200米,因此,在构建应用程序时,几秒钟/一分钟的时间我应该收到更新证明吗?还是我需要先离开篱笆然后再进入?我该如何解决此问题...

我的代码:

            // shiny doesn't usually manage your viewmodels, so we'll do this for now
        var geofences = ShinyHost.Resolve<IGeofenceManager>();
        var notifications = ShinyHost.Resolve<INotificationManager>();

        Register = new Command(async () =>
        {
            // this is really only required on iOS, but do it to be safe
            var access = await notifications.RequestAccess();
            if (access == AccessState.Available)
            {
                await geofences.StartMonitoring(new GeofenceRegion(
                    "CN Tower - Toronto, Canada",
                    new Position(52.079779, 4.337133),
                    Distance.FromMeters(200)
                )
                {
                    NotifyOnEntry = true,
                    NotifyOnExit = true,
                    SingleUse = false
                });
            }
        });



public class GeofenceDelegate : IGeofenceDelegate
{
    private readonly INotificationManager _notifications;

    public GeofenceDelegate(INotificationManager notifications)
    {
        _notifications = notifications;
    }

    public async Task OnStatusChanged(GeofenceState newStatus, GeofenceRegion region)
    {
        if (newStatus == GeofenceState.Entered)
        {
            await GeofenceEntered(region);
        }
        else if (newStatus == GeofenceState.Exited)
        {
            await GeofenceLeft(region);
        }
    }

}

我的代码与本教程完全相同,如果对它进行调试,则单击按钮时会创建地理围栏。所以一切对我来说都很好。

xamarin.forms shiny notifications geolocation geofencing
1个回答
0
投票

我有一个类似的问题,只是假设当您在栅栏内开始时,由于您已经在栅栏内,因此不会将您识别为进入/退出。

我必须走出/进入创建的围栏以触发'OnStatusChanged'方法。

重要的是,除非我的应用程序激活了手机的GPS系统(例如,定期重新请求当前位置),否则它不会进入方法,但是我不确定这是否是由我的旧屁股手机引起的(< [正在运行Android6.1),或者可以通过这种方式进行修复。

希望这会有所帮助;)
© www.soinside.com 2019 - 2024. All rights reserved.