简体   繁体   English

xamarin形成使用位置iOS的权限

[英]xamarin forms permission to use location iOS

I'm using Xamarin.Forms and creating an iOS App who has a background service to get a location each 10 minutes. 我正在使用Xamarin.Forms并创建一个具有后台服务的iOS应用,该应用每10分钟获取一次位置。

The code is working, my problem is when I access the App configuration on an IPad. 该代码有效,我的问题是当我在iPad上访问应用程序配置时。 It shows the permission for accesss the camera but not to access the current location. 它显示了访问摄像机但不访问当前位置的权限。

I think that will be a problem when I submit the App for review. 我认为当我提交应用程序进行审核时,这将是一个问题。

For initialize the location: 初始化位置:

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

For getting the location: 获取位置:

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();
    }
}

There are something that I forgot? 有什么我忘了吗

Did you add these keys to your Info.plist file? 您是否将这些密钥添加到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