/Beakn

A Swift library for iBeacon Monitoring

Primary LanguageSwiftMIT LicenseMIT

Beakn

CI Status Version License Platform

Usage

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

  • To be able to use the library, please follow below mentioned steps

    1. Import Beakn in to your app class

       import Beakn
      
    2. Assign your class as a delegate to the library

       BeaknManager.sharedManager.delegate = self
      
    3. Implement BeaknDelegate delegate methods

       extension ViewController: BeaknDelegate {
           func initializationFailed(error: NSError) {
               print("Unable to initialize BeaknManager due to error \(error)")
           }
      
           func entered(beakn:  Beakn) {
               let notification = UILocalNotification()
               notification.alertBody = "Entered iBeacon region"
               UIApplication.sharedApplication().presentLocalNotificationNow(notification)
               print("Device entered iBeacon region with identifier  \(beakn.identifier)")
           }
      
           func exited(beakn: Beakn) {
               let notification = UILocalNotification()
               notification.alertBody = "Exited iBeacon region"
               UIApplication.sharedApplication().presentLocalNotificationNow(notification)
      
               print("Device exited iBeacon region with identifier \(beakn.identifier)")
           }
      
           func monitoringFailedForRegion(beakn: Beakn, error: NSError) {
               print("Monitoring failed due to error \(error)")
           }
      
           func rangingComplete(beakns: [Beakn]) {
           }
      
           func rangingFailed(beakn: Beakn, error: NSError) {
           }
       }
      
    4. Request for iBeacon Region monitoring

       do {
           try BeaknManager.sharedManager.startMonitoringForBeakns([Beakn(uuid: kBeaconID, identifier: "Test iBeacon", major: .None, minor: .None)])
       } catch BeaknErrorDomain.AuthorizationError(let msg) {
           print(msg)
       } catch BeaknErrorDomain.InitializationError(let msg) {
           print(msg)
       } catch BeaknErrorDomain.InvalidBeaknInfo {
           print("Invalid Beakn info provided")
       } catch BeaknErrorDomain.InvalidUUIDString {
           print("Invalid UUID string provided")
       } catch BeaknErrorDomain.RegionMonitoringError(let msg) {
           print(msg)
       } catch {
           print("Unknown error occurred")
       }
      

Requirements

  • iOS 9.0+

  • Xcode 7.1+

  • You will have to enable location services capability for your app

  • You will have to add NSLocationAlwaysUsageDescription key with appropriate description in the App's info.plist file

Installation

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

pod 'Beakn' , '~> 1.1.0'

Future improvements

I'll add support for iBeacon Ranging in the upcoming release. Meanwhile, Please feel free to make any changes/improvements and submit PRs :)

Author

Prasad Pamidi, pamidi.dev@gmail.com

License

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