简体   繁体   English

无法在iOS9的swift2中获取航向数据(用于罗盘应用)

[英]Cannot get heading data (for compass app) in swift2 on ios9

Trying to get the basics of a simple compass app working in swift 2, using xcode 7 and testing in the ios simulator. 尝试获得在Swift 2中工作的简单罗盘应用程序的基础知识,使用xcode 7并在ios模拟器中进行测试。

I cannot seem to get the heading information. 我似乎无法获得标题信息。

My app currently prints GeoLocation data just fine, but does not print heading data. 我的应用程序当前可以很好地打印GeoLocation数据,但是不打印标题数据。

Contents of ViewController.swift: 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)
}
}

I have also added this to my Info.plist file as well as adding CoreLocation to my liked libraries. 我还将此添加到了Info.plist文件中,并将CoreLocation添加到了我喜欢的库中。

<key>NSLocationAlwaysUsageDescription</key>
<string>Lemmie have your location</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Gimmie</string>

Sample Console output looks like this: 控制台示例输出如下所示:

[<+37.33761534,-122.03479147> +/- 5.00m (speed 5.75 mps / course 271.71) @ 4/26/16, 1:31:07 AM British Summer Time] [<+ 37.33761534,-122.03479147> +/- 5.00m(速度5.75 mps /课程271.71)@ 16/4/26,英国夏令时上午]

[<+37.33761751,-122.03485278> +/- 5.00m (speed 5.32 mps / course 272.27) @ 4/26/16, 1:31:08 AM British Summer Time] [<+ 37.33761751,-122.03485278> +/- 5.00m(速度5.32 mps /课程272.27)@ 16/4/26,英国夏令时上午)

[<+37.33762005,-122.03491577> +/- 5.00m (speed 5.50 mps / course 272.11) @ 4/26/16, 1:31:09 AM British Summer Time] [<+ 37.33762005,-122.03491577> +/- 5.00m(速度5.50 mps /课程272.11)@ 4/26/16,1:31:09 AM英国夏令时间]

[<+37.33762244,-122.03497889> +/- 5.00m (speed 5.52 mps / course 271.42) @ 4/26/16, 1:31:10 AM British Summer Time] [<+ 37.33762244,-122.03497889> +/- 5.00m(速度5.52 mps /课程271.42)@ 4/26/16,1:31:10英国夏令时]

[<+37.33762300,-122.03504341> +/- 5.00m (speed 5.52 mps / course 270.29) @ 4/26/16, 1:31:11 AM British Summer Time] ... [<+ 37.33762300,-122.03504341> +/- 5.00m(速度5.52 mps /路线270.29)@ 4/26/16,1:31:11 AM英国夏令时] ...

I don't believe there is heading information available while running in the simulator. 我认为在模拟器中运行时,没有标题信息可用。 I tested your code and it works fine on my iPhone 6. 我测试了您的代码,并在iPhone 6上正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM