RxLocation
一个用于 iOS 定位的 RX 包装器。它简单而强大。
用法
选择权限
选择 authorizeWhenInUse
或 authorizeAlways
进行权限设置。
var rxLocation = RxLocation(authorization: .authorizeAlways)
当前位置
var rxLocation = RxLocation(authorization: .authorizeAlways)
rxLocation.requestCurrentLocation()
.subscribe(onNext: { location in
print(location)
})
位置更新
rxLocation.requestLocationUpdates()
.subscribe(onNext: { locations in
print(locations[0])
})
停止更新
当使用rxLocation.requestLocationUpdates()
时,您可以用以下方式停止更新:
rxLocation.stopLocationUpdates()
位置管理器选项
您可以为主机CLLocationManager
设置任何选项,例如
rxLocation.locationManager.showsBackgroundLocationIndicator = true
示例
要运行示例项目,请首先克隆存储库,然后在示例目录中运行pod install
。
安装
RxLocation 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile
pod 'RxLocation'
作者
ShabanKamell, [email protected]
许可
RxLocation 在 Apache 许可证 v2.0 下提供。有关更多信息,请参见 LICENSE 文件。