Giter Site home page Giter Site logo

imaware's Introduction

ImAware

CI Status Version License Platform

Example

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

Requirements

Installation

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

pod 'ImAware'

Example

Getting current Hardware context

//Return battery level as a Float
let batteryLevel = Snapshot.hardware.batteryLevel
//Returns a Bool to indicate phones plugged in or not
let headphoneOn = Snapshot.hardware.headphonetPluggedIn
//Returns brightness level as a float
let brightness = Snapshot.hardware.screenBrightness
//Returns a Bool indicating Low Power Mode state
let powerModeOn = Snapshot.hardware.powerModeEnabled
//Return a list of connected hardware
let connectedAcessories = Snapshot.hardware.connectedAcessories
//Returnss a % of free space in the system
let availableSpace = Snapshot.hardware.availableSpace

Getting current user location context

Snapshot.location.getUserCurrentLocation(accuracy: .room) { (location, error) in
    guard let userLocation = location else{
        print(error?.localizedDescription)
        return
    }
}

Getting current user nearby adresses

Snapshot.location.getNearbyPlaces { (placemarks) in
    guard let userNearbyAdresses = placemarks else {
        return
    }
}

Getting current user activity context

Snapshot.activity.getCurrentUserActivity { (activityType) in
    print(activityType.rawValue)
}

Observing user Hardware context

//You can observe a single sensor
Observer.hardware.observeSensor(sensor: .batteryLevel, withInterval: 100) { (value, error) in
    guard let batteryLevel = value as? Float else { return }
    print("A bateria possui \(batteryLevel)% de carga")
}

//Or multiple
Observer.hardware.observeMultipleSensors(sensors: [.batteryLevel,.headphoneConnected], withInterval: 100) { (values, error) in
    guard let batteryLevel = values[.batteryLevel] as? Float, let headphoneStatus = values[.headphoneConnected] as? Bool else { return }

    print("Você possui \(batteryLevel)% de bateria")
    print("Os headphones estão \(headphoneStatus ? "plugados" : "desplugados")")
}

Observing user Location context

//Register a fence
Observer.location.createFence(withLatitude: 37.33170, longitude: -122.030237, radius: 200, identifier: "FenceWithMessage", fenceType: .uponEnter, payload: ["Message" : "I've entered Apple"])
//Create a class that subscribes to RegionChange protocol to receive fence updates
class locationObserver: RegionChange {
    var aware = AwareLocation.shared

    init() {
        aware.fenceDelegate = self
    }

    func fenceStatusDidChange(forFence fence: LocationFence) {
        if fence.identifier == "FenceWithMessage" {
        guard let fencePayload = fence.payload else { return }
        guard let message = fencePayload["Message"] as? String else { return }
            print(message)
        }
    }
}

//Stop monitoring fence
Observer.location.stopMonitoringFence(withIdentifier: "FenceWithMessage")

Author

Yuri Frota , [email protected]

License

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

imaware's People

Contributors

trastoan avatar

Watchers

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