Code Monkey home page Code Monkey logo

ios-beacon-tools's Introduction

iOS Beacon Tools

This project contains iOS utilities to scan for and decode beacons using AltBeacon and Eddystone formats that are not natively supported by iOS.

This code detects AltBeacon, Eddystone-UID, Eddystone-URL, Eddystone-TLM and Eddystone-EID (without resolution)

Overview

By copying this code into your project, you can use the singleton RNLBeaconScanner class to scan for bluetooth beacon and then periodically read out the beacons that are detected. Detected beacons can be access from an array on the scanner.trackedBeacons() method.

This list of detected beacons is updated internally as beacons come in, and the code provides no callbacks. You'll need to some way to run code periodically to read the list of detected beacons.

Setup

  1. Copy all the files in the beacon-tools folder into your project
  2. If using Swift, add at least the following to your PROJECTNAME-Bridging-Header.h file.
#include "RNLBeaconScanner.h"
#include "RNLURLBeaconCompressor.h"
#include "RNLBeacon+Distance.h"

Example

class Sample {
    var scanner: RNLBeaconScanner?
    func sample() {
        scanner = RNLBeaconScanner.shared()
        scanner?.startScanning()
        
        // Execute this code periodically (every second or so) to view the beacons detected

        if let detectedBeacons = scanner?.trackedBeacons() as? [RNLBeacon] {
            for beacon in detectedBeacons {
                if (beacon.beaconTypeCode.intValue == 0xbeac) {
                    // this is an AltBeacon
                    NSLog("Detected AltBeacon id1: %@ id2: %@ id3: %@", beacon.id1, beacon.id2, beacon.id3)
                }
                else if (beacon.beaconTypeCode.intValue == 0x00 && beacon.serviceUuid.intValue == 0xFEAA) {
                    // this is eddystone uid
                    NSLog("Detected EDDYSTONE-UID with namespace %@ instance %@", beacon.id1, beacon.id2)
                }
                else if (beacon.beaconTypeCode.intValue == 0x10 && beacon.serviceUuid.intValue == 0xFEAA) {
                    // this is eddystone url
                    NSLog("Detected EDDYSTONE-URL with %@", RNLURLBeaconCompressor.urlString(fromEddystoneURLIdentifier: beacon.id1))
                }
                else {
                    // some other beacon type
                }
            }
        }        
    }
}

TODOs:

  1. Add better documentation
  2. Convert the code into Swift
  3. Make this a framework so you don't have to copy the source

License

This code is open source under the Apache 2 license. See LICENSE file in this repo.

Bugs? Problems?

Open an issue on this project, or a question on StackOverflow.com

ios-beacon-tools's People

Contributors

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