STLocationRequest 3.3.1

STLocationRequest 3.3.1

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最新发布2019年4月
SPM支持SPM

Sven Tiigi维护。



Logo


STLocationRequest

Swift 5.0 Build Status Version Carthage Compatible Platform Downloads
Maintainability Documentation Twitter

STLocationRequest 以优雅的方式在创作品牌首次请求用户的地理位置服务。 STLocationRequestController在一个美丽的3D 360°飞越-地图视图中显示,该视图建立在 FlyoverKit 上,并具有超过25个城市和地标。

Preview GIF

安装

CocoaPods

STLocationRequest可通过CocoaPods使用。要安装它,只需将以下行添加到您的Podfile

pod 'STLocationRequest'

Carthage

Carthage是一个去中心化的依赖管理器,它会构建您的依赖并提供二进制框架。

您可以使用以下命令通过Homebrew安装Carthage

$ brew update
$ brew install carthage

要使用Carthage将STLocationRequest整合到Xcode项目中,请在您的Cartfile中指定它

github "SvenTiigi/STLocationRequest"

运行carthage update --platform iOS以构建框架,并将构建好的拖入Xcode项目中。

  • STLocationRequest框架
  • FlyoverKit框架

到您的Xcode项目中。

在您的应用目标的“编译阶段”设置选项卡中,点击“+”图标,选择“新建运行脚本阶段”,并根据Carthage入门步骤4、5和6提到的内容添加框架路径(所有框架)。

使用

import STLocationRequest

// Initialize STLocationRequestController with STLocationRequestController.Configuration
let locationRequestController = STLocationRequestController { (config: inout STLocationRequestController.Configuration) in
    config.title.text = "We need your location for some awesome features"
    config.allowButton.title = "Alright"
    config.notNowButton.title = "Not now"
    config.mapView.alpha = 0.9
    config.backgroundColor = UIColor.lightGray
    config.authorizeType = .requestWhenInUseAuthorization
}

// Get notified on STLocationRequestController.Events
locationRequestController.onEvent = { event in
    if case .locationRequestAuthorized = event {
        // Location Request Authorized 🙌
    }
}

// Present STLocationRequestController
locationRequestController.present(onViewController: self)

请注意,3D飞行视角仅在真实iOS设备上工作(了解更多信息)。

配置

可以通过STLocationRequestController.Configuration结构体来自定义STLocationRequestController,有许多选项可供选择。👨‍💻更多详细信息请参见此处

事件监听

如果发生了STLocationRequestController.Event,将会调用onEvent函数。只需设置一个类型为(Event) -> Void的匿名函数来评估事件。

locationRequestController.onEvent = { (event: STLocationRequestController.Event) in
    switch event {
        case .locationRequestAuthorized:
            break
        case .locationRequestDenied:
            break
        case .notNowButtonTapped:
            break
        case .didPresented:
            break
        case .didDisappear:
            break
    }
}

或者直接传递一个函数👌

locationRequestController.onEvent = onLocationRequestControllerEvent

func onLocationRequestControllerEvent(_ event: STLocationRequestController.Event) {
    // Evaluate the event
}

Info.plist

为了进行位置请求,您必须在其Info.plist文件中定义一个使用描述。

STLocationRequestController.Authorization.requestWhenInUseAuthorization

<key>NSLocationWhenInUseUsageDescription</key>
<string>The usage description</string>

STLocationRequestController.Authorization.requestAlwaysAuthorization

<key>NSLocationAlwaysUsageDescription</key>
<string>The usage description</string>

使用描述将在默认iOS位置请求对话框中显示,这将在用户点击允许按钮时出现。

推荐呈现

推荐展示 STLocationRequestController 的方式如下。

if STLocationRequestController.shouldPresentLocationRequestController {
    // Location Services are enabled and authorizationStatus is notDetermined
    // Ready to present STLocationRequestController
    self.presentLocationRequestController()
}

iOS 模拟器

请注意,只有安装了至少 iOS 9.0 的真实 iOS 设备才能使用 3D 飞越视图(Apple 开发者 API 参考)。使用运行 STLocationRequestControlleriOS 模拟器 拍摄的截图可以展示 iOS 模拟器的行为。

iOSSimulatorBehavior

依赖项

STLocationRequest 使用以下库。

贡献

欢迎贡献🙌 🤓

示例应用

要运行示例应用,您需要首先通过 Carthage 生成 Framework。

$ carthage update --platform iOS
$ open STLocationRequest.xcodeproj

许可协议

STLocationRequest
Copyright (c) 2019 Sven Tiigi <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.