Ios 应用程序没有';安装时使用时,是否询问位置服务许可?
我正在我的应用程序中使用谷歌地图。我已在info.plist中设置了此项 隐私-使用时的位置使用说明 在我的代码(主屏幕)中,我也这样检查:Ios 应用程序没有';安装时使用时,是否询问位置服务许可?,ios,swift,cllocationmanager,locationmanager,location-services,Ios,Swift,Cllocationmanager,Locationmanager,Location Services,我正在我的应用程序中使用谷歌地图。我已在info.plist中设置了此项 隐私-使用时的位置使用说明 在我的代码(主屏幕)中,我也这样检查: if (CLLocationManager.locationServicesEnabled()) { locationManager = CLLocationManager() locationManager.delegate = self locationManager.desiredAccura
if (CLLocationManager.locationServicesEnabled())
{
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestAlwaysAuthorization()
locationManager.startUpdatingLocation()
} else{
let alertController = UIAlertController(title: "Oops !!" , message: "Location service seems to be disabled. Please enable from Settings -> Privacy ->LocationService.", preferredStyle: .Alert)
let defaultAction = UIAlertAction(title: "OK", style: .Default, handler: nil)
alertController.addAction(defaultAction)
self.presentViewController(alertController, animated: true, completion: nil)
}
但在第一次安装该应用程序时,它不会请求许可。任何帮助都是值得的
import CoreLocation
class AppDelegate: CLLocationManagerDelegate{
var locationManager: CLLocationManager!
var currentCoordinate: CLLocationCoordinate2D?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
self.setupLocationManager()
return true
}
func setupLocationManager(){
locationManager = CLLocationManager()
locationManager?.delegate = self
self.locationManager?.requestAlwaysAuthorization()
locationManager?.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
locationManager?.startUpdatingLocation()
}
// Below method will provide you current location.
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
if currentCoordinate == nil {
currentCoordinate = locations.last?.coordinate
locationManager?.stopMonitoringSignificantLocationChanges()
let locationValue:CLLocationCoordinate2D = manager.location!.coordinate
print("locations = \(locationValue)")
//currentCoordinate use this location Coordinate in your whole app.
locationManager?.stopUpdatingLocation()
}
}
// Below Mehtod will print error if not able to update location.
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
print("Error")
}
如果根据我的回答有任何疑问,请告诉我
如果有任何查询符合我的答案,请告诉我。您正在设置
Info.plist
键,用于在用户使用应用程序时(即,当它位于前台时)访问位置,但在您的代码中,您在应用程序运行时请求权限(即始终)
你需要决定你想要哪个。如果希望始终能够访问用户的位置,请更改
Info.plist
键。如果您想在应用程序位于前台时访问用户的位置,请将权限请求改为requestwhenuseauthorization()
。您正在设置Info.plist
键,用于在用户使用应用程序时(即在前台时)访问位置,但在您的代码中,无论应用程序何时运行(即始终),您都在请求权限
你需要决定你想要哪个。如果希望始终能够访问用户的位置,请更改
Info.plist
键。如果您想在应用程序位于前台时访问用户的位置,请将权限请求改为requestwhenuseauthorization()
。从iOS 10开始,我们需要在.plist文件中授予位置权限,如下所示
只需在设置中检查应用的位置服务是否启用。设置->应用名称->允许位置访问。不应选择“从不”
从设备中删除你的应用程序并重新安装应用程序,然后它会询问你位置权限。从iOS 10开始,我们需要在.plist文件中授予位置权限,如下所示 只需在设置中检查应用的位置服务是否启用。设置->应用名称->允许位置访问。不应选择“从不”
从设备中删除你的应用程序并重新安装应用程序,然后应用程序应询问你的位置权限。你添加的内容是否能够检测你是否正在驾驶,我们需要访问你的位置。在.plist文件中?只需在appdelegates.swift中设置此代码file@HimanshuMoradiya要在AppDelagate中添加哪些代码?请查看此答案-您添加哪些代码是为了能够检测您是否正在驾驶,我们需要访问您的位置。在.plist文件中?只需在appdelegates.swift中设置此代码file@HimanshuMoradiya在AppDelagate中添加哪些代码?看看这个答案-@AnushkaMadushan这起作用了,那么为什么要放弃投票?很抱歉,我该如何更改it@AnushkaMadushan请接受我的回答。现在,它不会让你倒下vote@AnushkaMadushan如果您的问题解决了,请批准答案。快乐编码。@AnushkaMadushan这是可行的,那么为什么要给你们投票?很抱歉,我怎么能改变呢it@AnushkaMadushan请接受我的回答。现在,它不会让你倒下vote@AnushkaMadushan如果您的问题解决了,请批准答案。快乐编码。