Git Product home page Git Product logo

stlocationrequest's Introduction

STLocationRequest

Swift 4.0 Version License Platform Downloads Twitter

Demo GIF


Description

STLocationRequest is a simple and elegant way to request the users location services at the very first time written in Swift. The STLocationRequestController shows a beautiful 3D 360° Flyover MapView with over 25 cities and landmarks 🗺.



Installation

STLocationRequest is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'STLocationRequest', '~> 3.0'

Usage

import STLocationRequest

// Initialize STLocationRequestController with STLocationRequestController.Configuration
let locationRequestController = STLocationRequestController { config in
    config.titleText = "We need your location for some awesome features"
    config.allowButtonTitle = "Alright"
    config.notNowButtonTitle = "Not now"
    config.mapViewAlpha = 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)

Please keep in mind that the 3D flyover view will only work on a real iOS device (Read more).

Configuration

The STLocationRequestController can be customized via the the STLocationRequestController.Configuration struct. There are plenty of options available 👨‍💻 More details can be found here

OnEvent

The onEvent closure allows you to get notified if an STLocationRequestController.Event occured. For example to detect if the user has authorized or denied the location request or tapped the Not Now Button.

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

Or just simply pass a function 👌

locationRequestController.onEvent = onLocationRequestControllerEvent

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

Info.plist

In order to perform a location request you have to define a usage description in your Info.plist file.

STLocationRequestController.Authorization.requestWhenInUseAuthorization

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

STLocationRequestController.Authorization.requestAlwaysAuthorization

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

The usage description will be shown in the default iOS location request dialog, which will show up when the user tapped the allow button.

Presenting-Recommendation

The recommended way to present STLocationRequestController is the following way.

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

iOS Simulator

Please keep in mind that the 3D flyover view will only work on a real iOS device with at least iOS 9.0 installed (Apple Developer API Reference). A Screenshot taken from an iOS Simulator running a STLocationRequestController visualizes the iOS Simulator behaviour.

iOSSimulatorBehavior

Dependencies

STLocationRequest is using following libraries.

Contributing

Contributions are very welcome 🙌 🤓

License

STLocationRequest
Copyright (c) 2018 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.

stlocationrequest's People

Contributors

giulio92 avatar grodowski avatar oooseun avatar rico237 avatar sventiigi avatar wjiuxing avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.