【问题标题】:xam.plugin.geolocator doesn't work in iosxam.plugin.geolocator 在 ios 中不起作用
【发布时间】:2021-02-11 01:25:14
【问题描述】:

我尝试在位置变化时听,应用程序检测到它。 在android上运行良好,但在ios上却不行 我关注了这个:https://docs.microsoft.com/en-us/xamarin/essentials/geolocation?tabs=ios

async Task StartListening()
        {
            await DisplayAlert("1", "moving", "OK");

            await CrossGeolocator.Current.StartListeningAsync(TimeSpan.FromSeconds(5), 10, true, new Plugin.Geolocator.Abstractions.ListenerSettings
            {
                ActivityType = Plugin.Geolocator.Abstractions.ActivityType.AutomotiveNavigation,
                AllowBackgroundUpdates = true,
                DeferLocationUpdates = true,
                DeferralDistanceMeters = 1,
                DeferralTime = TimeSpan.FromSeconds(1),
                ListenForSignificantChanges = true,
                PauseLocationUpdatesAutomatically = false

            });
            await DisplayAlert("2", "moving", "OK");

            CrossGeolocator.Current.PositionChanged += PositionChangedAsync;
        }

第一个警报有效,但第二个无效。 需要帮助

【问题讨论】:

    标签: ios xamarin xamarin.ios


    【解决方案1】:

    我已经检查了本地站点中的共享代码,它可以正常工作。

    确保您的info.plist 应包含以下内容:

    <key>UIBackgroundModes</key>
    <array>
        <string>location</string>
    </array>
    <key>NSLocationAlwaysUsageDescription</key>
    <string>This app needs access to location when in the background.</string>
    <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
    <string>This app needs access to location when open and in the background.</string>
    

    【讨论】:

    • 谢谢我把钥匙放在没有&lt;key&gt;UIBackgroundModes&lt;/key&gt; &lt;array&gt; &lt;string&gt;location&lt;/string&gt; &lt;/array&gt;
    【解决方案2】:

    我也有类似的问题。

    在 iOS 14 上运行,CrossGeolocator.Current.StartListeningAsync 会显示一个弹出窗口,说明应用正在使用后台位置,并提供保留该权限或将其更改为仅在应用中使用的选项。

    在选择一个选项(任何选项)时,CrossGeolocator.Current.StartListeningAsync 永远不会返回并且后续代码不会执行。

    如果我终止应用程序并使用手动设置的权限重新启动它,回调将起作用。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-04
    • 2011-06-14
    相关资源
    最近更新 更多