繁体   English   中英

xamarin形成使用位置iOS的权限

[英]xamarin forms permission to use location iOS

我正在使用Xamarin.Forms并创建一个具有后台服务的iOS应用,该应用每10分钟获取一次位置。

该代码有效,我的问题是当我在iPad上访问应用程序配置时。 它显示了访问摄像机但不访问当前位置的权限。

我认为当我提交应用程序进行审核时,这将是一个问题。

初始化位置:

this.locMgr = new CLLocationManager();
if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
{
    locMgr.RequestAlwaysAuthorization(); // works in background
    //locMgr.RequestWhenInUseAuthorization (); // only in foreground
}

获取位置:

if (CLLocationManager.LocationServicesEnabled) 
{
    if (CLLocationManager.Status==CLAuthorizationStatus.Authorized 
     || CLLocationManager.Status==CLAuthorizationStatus.AuthorizedAlways)
    {
        //set the desired accuracy, in meters
        LocMgr.DesiredAccuracy = 1;
        LocMgr.LocationsUpdated += (object sender, CLLocationsUpdatedEventArgs e) =>
        {
            _currentLocation = (e.Locations[e.Locations.Length - 1]);
        };

        LocMgr.AuthorizationChanged += (object sender, CLAuthorizationChangedEventArgs e) =>
        {
            if (e.Status == CLAuthorizationStatus.Denied 
             || e.Status == CLAuthorizationStatus.Restricted)
            {
                LocMgr.StopUpdatingLocation();
                _currentLocation = null;
            }
        };

        LocMgr.StartUpdatingLocation();
    }
}

有什么我忘了吗

您是否将这些密钥添加到Info.plist文件中?

<key>NSLocationAlwaysUsageDescription</key>
<string>Your message goes here</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Your message goes here</string>

暂无
暂无

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

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