Lui*_*lli 1 geolocation cllocationmanager ios xamarin xamarin.forms
我正在使用Xamarin.Forms并创建一个拥有后台服务的iOS应用程序,每10分钟获取一个位置.
代码正常,我的问题是当我在IPad上访问App配置时.它显示访问摄像机但不访问当前位置的权限.
我认为,当我提交应用程序进行审核时,这将是一个问题.
用于初始化位置:
this.locMgr = new CLLocationManager();
if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
{
locMgr.RequestAlwaysAuthorization(); // works in background
//locMgr.RequestWhenInUseAuthorization (); // only in foreground
}
Run Code Online (Sandbox Code Playgroud)
获取位置:
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();
}
}
Run Code Online (Sandbox Code Playgroud)
我忘记了什么?
小智 7
您是否将这些密钥添加到Info.plist文件中?
<key>NSLocationAlwaysUsageDescription</key>
<string>Your message goes here</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Your message goes here</string>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2683 次 |
| 最近记录: |