【问题标题】:How to create an Observable from CLLocationManager updates如何从 CLLocationManager 更新创建 Observable
【发布时间】:2016-04-09 21:11:53
【问题描述】:

我在我的应用程序中使用RxSwift 库。我正在尝试转换我的应用程序逻辑以处理 GPS 位置更新并将其移至可观察对象。为此,我一直使用此代码作为基线: https://github.com/ReactiveX/RxSwift/blob/master/RxExample/RxExample/Examples/GeolocationExample/GeolocationViewController.swift

但是,在上面的代码中,更新通过 UIView 扩展直接传递到 UIElement。这对我没有用,因为我需要将这些更新传递给非 UI 观察者变量以进行进一步的后台处理。

我是 RxSwift 的新手,我不知道在这种情况下如何构建我需要的 Observer 类型。我也无法在 RxSwift 文档中找到它。

如果有人可以评论如何使用 RxSwift 实现 CLLocationManager 的实现,我将不胜感激。

【问题讨论】:

    标签: swift cllocationmanager rx-swift


    【解决方案1】:

    发现不需要创建 Observer,observable 本身有以下可能性:

    let geolocationObservable = geolocationService.location .drive(onNext: { (location: CLLocation) in print(location.altitude) }, onCompleted: { //TODO }) { //TODO }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-13
      • 1970-01-01
      相关资源
      最近更新 更多