[英]Cannot get heading data (for compass app) in swift2 on ios9
尝试获得在Swift 2中工作的简单罗盘应用程序的基础知识,使用xcode 7并在ios模拟器中进行测试。
我似乎无法获得标题信息。
我的应用程序当前可以很好地打印GeoLocation数据,但是不打印标题数据。
ViewController.swift的内容:
import UIKit
import CoreLocation
class ViewController: UIViewController, CLLocationManagerDelegate{
var lm = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
lm.desiredAccuracy=kCLLocationAccuracyBest
lm.delegate = self
lm.requestWhenInUseAuthorization()
lm.startUpdatingHeading()
lm.startUpdatingLocation()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func locationManager(manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) {
print(newHeading)
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]){
print(locations)
}
}
我还将此添加到了Info.plist文件中,并将CoreLocation添加到了我喜欢的库中。
<key>NSLocationAlwaysUsageDescription</key>
<string>Lemmie have your location</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Gimmie</string>
控制台示例输出如下所示:
[<+ 37.33761534,-122.03479147> +/- 5.00m(速度5.75 mps /课程271.71)@ 16/4/26,英国夏令时上午]
[<+ 37.33761751,-122.03485278> +/- 5.00m(速度5.32 mps /课程272.27)@ 16/4/26,英国夏令时上午)
[<+ 37.33762005,-122.03491577> +/- 5.00m(速度5.50 mps /课程272.11)@ 4/26/16,1:31:09 AM英国夏令时间]
[<+ 37.33762244,-122.03497889> +/- 5.00m(速度5.52 mps /课程271.42)@ 4/26/16,1:31:10英国夏令时]
[<+ 37.33762300,-122.03504341> +/- 5.00m(速度5.52 mps /路线270.29)@ 4/26/16,1:31:11 AM英国夏令时] ...
我认为在模拟器中运行时,没有标题信息可用。 我测试了您的代码,并在iPhone 6上正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.