[英]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.