ios - xamarin 形成使用位置 iOS 的权限

标签 ios xamarin geolocation cllocationmanager xamarin.forms

我正在使用 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>

关于ios - xamarin 形成使用位置 iOS 的权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29898277/

相关文章:

xamarin - 从 native Android Xamarin 访问 Application.Current.Properties

框架回调传递接口(interface)时出现 Xamarin 异常

qt - MapItemView 在 dataChanged 信号后不更新

iOS swift native 谷歌共享错误消息,因为用户必须登录

ios - Xcode 5 SpriteKit 粒子发射器未出现在编辑器中

iOS - fatal error : unexpectedly found nil while unwrapping an Optional value when reloadData() is called

ios - 取消 SKDownload 的最佳方法

android - 在应用程序请求位置权限之前创建弹出警报的问题

android - 如何将定位模式从默认模式更改为 "high accuracy/battery saving"(仅限设备)

html - Dart中的HTML5地理位置