Code Monkey home page Code Monkey logo

geologger's Introduction

GeoLogger

Build and test Version License Platform codecov

Example

A package to log location events.

Installation

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

pod 'GeoLoggerSDK'

Add the following to your info.plist file

    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
    </dict>
    <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
    <string>The app needs both when in use and background location permission</string>
    <key>NSLocationTemporaryUsageDescriptionDictionary</key>
    <dict>
        <key>TemporaryAccuracyAuthPurposeKey</key>
        <string>This app needs accurate location so it can verify that you&apos;re in a supported region.</string>
    </dict>
    <key>NSLocationUsageDescription</key>
    <string>The app needs always location permission</string>
    <key>NSLocationWhenInUseUsageDescription</key>
    <string>The app needs when in use location permission</string>

These keys include background, foreground and precise location permission keys. You can modify the strings for these keys according to your project and requirement

Usage

iOS and MacOS

Additional steps are required to add background location access.

  • Go to your project -> Signing & Capabilities -> + Capability and add Background Modes capability
  • Tick Location updates checkbox

Requirements

Min iOS build target - iOS14.4
Min MacOS build target - MacOS 11.0

Implementation

Add the following import at the top of your file

import GeoLogger

  • For SwiftUI apps add the following setup code to your @main struct
var body: some Scene {
       WindowGroup {
           ContentView()
       }.onAppear {
           GeoLogger.setup()
       }
   }
  • For storyboard based apps add the following to your application(_:didFinishLaunchingWithOptions:) in AppDelegate.swift
GeoLogger.setup()
Next

You will need to ask the user for location permissions. Depending on your app and use case you can decide when and where you would like to do that. To request for location permissions call requestPermission method from the SDK

GeoLogger.requestPermission(true, requestTemporaryFullAccuracy: true) { (locationPermissionDenied, locationServicesDisabled) in }

Parameters:

  • allowBackgroundLocationTracking: Passing true will ask the user for background permissions
  • requestTemporaryFullAccuracy: Passing true will ask the user for temporary precise location permission if not provided

Within the callback you get 2 parameters depending on the location access situation.

  • locationPermissionDenied: True when the user has denied location permission for your app completely
  • locationServicesDisabled: True when location services are disabled on the device

You can use these parameters to show an alert and in case of iOS open settings to prompt the user to grant location permissions to your app.

If the user has provided location permission to your app even bare minimum then this callback will not be called

Finall call the log method to register current location log

GeoLogger.log(api: "<Your POST api url>") { (success, retryCount) in }

This method will create a post request pointed to the provided URL and send current location coordinates along with the timestamp.

The library implements batch uploading and has a persistant Realm storage built in where it stores all the logs and syncs them max 3 at a time whenever the time is appropriate.

In case of an error the SDK will try to register the log again for retryOnErrorCount times.

If the log registration fails after retryOnErrorCount is expired(or is 0) then the log will be deleted from the storage.

In the callback you will be able to monitor the success and retryCount of the registered log.

Author

nishiths23, [email protected]

License

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

geologger's People

Contributors

nishiths23 avatar

Watchers

 avatar  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.