Code Monkey home page Code Monkey logo

swiftbackgroundlocation's Introduction

SwiftBackgroundLocation

CI Status Version License Platform

SwiftBackground is the right choice to work easily and efficiently with Location Manager when your app is terminated or killed. It's based on region monitoring. Demo how it works (blue is normal tracking, red line is region based tracking):

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Just add in your app delegate for background location:

    var backgroundLocationManager = BackgroundLocationManager()
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
        
         backgroundLocationManager.startBackground() { result in
                if case let .Success(location) = result {
                    LocationLogger().writeLocationToFile(location: location)
                }
        }

        return true
    }

You can set up radius for background location:

    let regionConfig = RegionConfig(regionRadius: 25.0)
    var backgroundLocationManager = BackgroundLocationManager(regionConfig: regionConfig) 
    

Getting permission (.always or .whenInUse) for location tracking:

locationManager.manager(for: .always, completion: { result in
            if case let .Success(manager) = result {
                
            }


})

Location tracking with listener:

locationManager.manager(for: .always, completion: { result in
            if case let .Success(manager) = result {
                manager.startUpdatingLocation(isHeadingEnabled: true) { [weak self] result in
                    if case let .Success(locationHeading) = result, let location = locationHeading.location {
                        self?.updateLocation(location: location)
                    }
                }
            }

})

Getting heading needs additional hardware and hence wont work on simulator.

Requirements

Installation

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

pod "SwiftBackgroundLocation"

You must add NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription key to your project’s Info.plist containing the message to be displayed to the user at the prompt. If you need always location, you should add both.

<key>NSLocationAlwaysUsageDescription</key>
<string>$(PRODUCT_NAME) needs location always usage for recording in background.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>$(PRODUCT_NAME) needs location when in use for recording in foreground.</string>

The user will not be prompted unless one of these are added to the Info.plist.

Author

yoman07, [email protected]

License

SwiftBackgroundLocation is available under the MIT license. See the LICENSE file for more info.

Contact & Questions

If you have any questions, fell free to send me a mail. You can also fork this project, or open an issue

Contributions

SwiftBackgroundLocation is currently lead by:

  • Roman Barzyczak (GitHub <https://github.com/yoman07__ Roman Barzyczak <https://github.com/yoman07>__)

with contributions from:

  • Andrew Sowers <https://github.com/asowers1>__

swiftbackgroundlocation's People

Contributors

asowers1 avatar josa42 avatar yoman07 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.