我在iOS/xamarin应用程序中工作。(iOS 8)。我使用本教程来了解用户位置:http://www.themethodology.net/2014/10/getting-permission-to-access-user.html
下面的代码用于了解用户是否启用了定位服务,以及应用程序是否被授权使用该位置。
CLLocationManager clm = new CLLocationManager ();
public bool LocationServicesEnabled {
get {return CLLocationManager.LocationServicesEnabled;}
}
public bool IsAuthorized {
get {return CLAuthorizationStatus.Authorized == _authstatusLast;}
}
但是,如果用户第一次选择:不允许,之后,他在中更改权限
Privacy >> Location >> MyApp >> ON
IsAuthorized
方法始终为false。有人知道如何解决这个问题?
我找到了一种方法来了解应用程序是否有权使用定位服务(如果启用了服务,则没有)。
public bool IsAuthorized {
get {return CLLocationManager.Status == CLAuthorizationStatus.AuthorizedWhenInUse ;}
}
当应用程序使用AuthorizeWhenIsInUser
时,您可以使用CLAuthorizationStatus.AuthorizedWhenInUse
,如果您使用AuthorizedAlways
,则需要在CLAutorizationStatus
中更改。此外,对于iOS 8,有必要修改plist
文件中的密钥:有关plist的更多信息,请点击此处。http://www.themethodology.net/2014/10/getting-permission-to-access-user.html