Ios 我的核心定位器赢了';行不通
在过去的两个小时里,我一直在想为什么核心定位器找不到我的设备位置。Ios 我的核心定位器赢了';行不通,ios,swift,authorization,core-location,cllocationmanager,Ios,Swift,Authorization,Core Location,Cllocationmanager,在过去的两个小时里,我一直在想为什么核心定位器找不到我的设备位置。事实是: -它在emulator或我的iPhone上不起作用 -我可以接受应用程序来访问我在应用程序中的位置,但之后什么都不会发生 -我正在使用Swift和Xcode 6.4 -我已将NSLocationWhenUsageDescription和NSLocationAlwaysUsageDescription输入到我的信息中。plist import UIKit import MapKit import CoreLocation
事实是:
-它在emulator或我的iPhone上不起作用
-我可以接受应用程序来访问我在应用程序中的位置,但之后什么都不会发生
-我正在使用Swift和Xcode 6.4
-我已将NSLocationWhenUsageDescription和NSLocationAlwaysUsageDescription输入到我的信息中。plist
import UIKit
import MapKit
import CoreLocation
class satelliteViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {
@IBOutlet weak var mapView: MKMapView!
@IBOutlet weak var mapTypeTitle: UIButton!
var locationManager: CLLocationManager?
override func viewDidLoad() {
super.viewDidLoad()
locationManager = CLLocationManager()
locationManager!.delegate = self
locationManager!.desiredAccuracy = kCLLocationAccuracyBest
locationManager!.requestWhenInUseAuthorization()
locationManager!.startUpdatingLocation()
}
@IBAction func changeMapType(sender: AnyObject) {
// Unimportant
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
您只需始终或在使用应用程序时输入inside>settings>your app>location>即可启用应用程序的定位服务。祝您度过愉快的一天。在
info.plist
中,添加两个属性:NSLocationAlwaysUsageDescription
和nsLocationWhenUsageDescription
类似
然后检查ios版本是否为8.0或更高
if([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
{
[locationManager requestWhenInUseAuthorization];
[locationManager requestAlwaysAuthorization];
}
这是目标c,转换成swift
并确保已从“设置”应用为您的应用打开位置服务
确保设置了正确的委托并实现了必要的方法
希望这会有所帮助:)您是否实现了诸如
didUpdateLocation
之类的委托函数?我以前添加了didUpdateLocation、didFailWithError和didChangeAuthorizationStatus函数,但它似乎没有做任何事情。您可以向我们展示这些函数的代码吗?我已经让它工作了,谢谢你的帮助:)不幸的不是这样。在我接受应用程序访问我的位置后,它已将其设置为“在使用应用程序时”。无论您是否忘记导入类似于框架的核心位置,或者只是尝试从手机中删除应用程序并重新安装,它都会请求您允许位置服务,以及您在plist中提供的密钥消息他说他已经在他的Info.plist
中添加了这两个属性。然后他还需要添加我在回答中提到的代码。我给出了位置更新所需的全部场景。她**谢谢你的帮助,我最终回答了这个问题:)@Demi:不客气……)如果你认为这有帮助,那么接受答案,这样其他有类似问题的人也可以使用它。:)