簡體   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