ios - 无法在 ios9 上的 swift2 中获取航向数据(用于 compass 应用程序)

标签 ios iphone xcode swift compass

尝试获取在 swift 2 中运行的简单 compass 应用程序的基础知识,使用 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 (speed 5.75 mps / course 271.71) @ 4/26/16, 1:31:07 AM British Summer Time]

[<+37.33761751,-122.03485278> +/- 5.00m (speed 5.32 mps / course 272.27) @ 4/26/16, 1:31:08 AM British Summer Time]

[<+37.33762005,-122.03491577> +/- 5.00m (speed 5.50 mps / course 272.11) @ 4/26/16, 1:31:09 AM British Summer Time]

[<+37.33762244,-122.03497889> +/- 5.00m (speed 5.52 mps / course 271.42) @ 4/26/16, 1:31:10 AM British Summer Time]

[<+37.33762300,-122.03504341> +/- 5.00m (speed 5.52 mps / course 270.29) @ 4/26/16, 1:31:11 AM British Summer Time] ...

最佳答案

我认为在模拟器中运行时没有航向信息可用。我测试了您的代码,它在我的 iPhone 6 上运行良好。

关于ios - 无法在 ios9 上的 swift2 中获取航向数据(用于 compass 应用程序),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36853461/

相关文章:

iphone - Itunes Connect 无效的二进制文件

objective-c - UILabel 文本右对齐

ios - ReactiveCocoa 中的自动重复倒数计时器

ios - iOS > 8 中通过 TabBarVC 的透明 vc

iOS - 在 Localizable.strings 中用粗体字符串强调

iphone - 解析网站 API : How to query for objects incrementally?

Iphone屏幕视频捕捉

ios - 如何替换 NSMutableAttributedString 中的字符串?

objective-c - 不要播放声音

ios - XCode 中这个条形图上的渐变代表什么?