繁体   English   中英

iOS 13后台位置更新权限说明

[英]iOS 13 background location updates permission clarification

我正在努力让我的应用程序使用 iOS 13 上的“使用时”权限设置来获取后台位置更新。它在始终权限下工作得非常好,但我想要“使用时”。

有人告诉我,我只需要在 info plist 中启用后台模式。 我启用了这些,下面是我的信息列表中的片段。

<key>NSLocationAlwaysUsageDescription</key>
<string>Used for location services</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Need Permission</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Need Permission</string>

<key>UIBackgroundModes</key>
<array>
    <string>location</string>
    <string>remote-notification</string>
</array>

简而言之,在 iOS 13 中,是否可以使用临时的始终权限或使用时的权限来获取后台位置更新?

编辑:

下面是开始跟踪用户位置的 function:

 public static async Task StartJourneyTracking()
    {
        try
        {
            InitialiseJourney();
            if (Geolocator.IsListening) return;
            CLLocationManager manager = new CLLocationManager();
            manager.ShowsBackgroundLocationIndicator = true;
            Geolocator.DesiredAccuracy =                   
                  TrackingConstants.GeoLocatorDesiredAccuracy;
            await Geolocator.StartListeningAsync(TimeSpan.FromSeconds(
                TrackingConstants.GeoLocatorMinimumTime),
                TrackingConstants.GeoLocatorMinimumDistance, false, new 
                ListenerSettings()
                {
                    ActivityType = ActivityType.AutomotiveNavigation,
                    AllowBackgroundUpdates = true,
                    DeferLocationUpdates = false,
                    PauseLocationUpdatesAutomatically = false
                });
            IsLocationServiceRunning = true;

            Geolocator.PositionChanged += PositionChanged;
            Geolocator.PositionError += PositionError;
            ShowNotification();
        }
        catch (Exception e)
        {
            InstanceManager.LoggingHelper().TrackError(e);
        }
    }

2019 年 18 月 11 日更新

根据从评论中获得的建议,我看到了一些行为上的变化。

当应用程序在后台最小化时,临时始终许可旅程日志不会获取位置更新。 如果我让旅程日志在后台运行(没有获取位置更新)并等待第二个提示出现,要求在使用时保留或更改为始终。 选择何时使用会使后台位置指示条立即出现,并且旅程记录似乎能够在后台获取位置更新。

但是,如果我现在点击后台指示器栏,将应用程序置于前台并结束旅程记录(停止位置更新)并重新启动它(开始位置更新)而不更改权限,我将不再看到蓝色背景指示器栏和旅程logging 停止在后台接收位置更新。

有任何想法吗?

再次感谢

所以,原来地理定位器插件似乎没有正确配置 iOS 13 权限。 我为 iOS 的 CLLocationManager 切换了地理定位器,它第一次工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM