Swiftpack.co - kisi-inc/kisi-ios-st2u-framework as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
kisi-inc/kisi-ios-st2u-framework
iOS tap to unlock framework
.package(url: "https://github.com/kisi-inc/kisi-ios-st2u-framework.git", from: "0.1.3")

Kisi Secure Unlock

Integration

Kisi Secure Unlock is distributed as a swift package. To integrate it into your app simply add the repository as a package dependency in Xcode.

Permissions

Required

Secure unlock needs bluetooth permission and be able to act as a bluetooth peripheral while in background. So you need to add these to your Info.plist

<key>NSBluetoothAlwaysUsageDescription</key>
<string>Some string explaining to your users why you need bluetooth permission.</string>
<key>UIBackgroundModes</key>
<array>
    <string>bluetooth-peripheral</string>
</array>

You prompt the bluetooth permission dialog by simply initialising an CBCentralManager instance:

CBCentralManager(delegate: self, queue: .main, options: nil)

Optional

You can also optionally get permission to use location in background. This will improve the performance of tap to unlock under certain conditions.

<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Unlocking by tapping your phone against a Kisi reader will work better with always permission. Kisi doesn&apos;t store or share your location data.</string>
<key>UIBackgroundModes</key>
<array>
    <string>bluetooth-peripheral</string>
    <string>location</string>
</array>

You can then prompt the user for location permission

let locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.requestAlwaysAuthorization()

Usage

Import the package

import SecureUnlock

In didFinishLaunchingWithOptions start the secure unlock manager and set the delegate

SecureUnlockManager.shared.start()
SecureUnlockManager.shared.delegate = self

SecureUnlockDelegate

You need to implemented the SecureUnlockDelegate protocol.

extension MyClass: SecureUnlockDelegate {
    func secureUnlockSuccess(online: Bool) {
        // Callback when unlock succeeds.
        // Online parameter indicates if it was an online or offline unlock.
    }
    
    func secureUnlockFailure(error: SecureT2UError) {
        // Login id callback. 
        // If you only support 1 login you can ignore the organization property and simply return the login id for the logged in user. Otherwise you must find the login id for the given organization.
    }
    
    func secureUnlockLoginIDForOrganization(_ organization: Int?) -> Int? {
        // Login id callback. 
        // If you only support 1 login you can ignore the organization property and simply return the login id for the logged in user. Otherwise you must find the login id for the given organization.
    }
    
    func secureUnlockPhoneKeyForLogin(_ login: Int) -> String? {
        // Phone key callback. 
        // The phone key is returned when you create a login object. See https://api.kisi.io/docs#/operations/createLogin.
    }
    
    func secureUnlockFetchCertificate(login: Int, reader: Int, online: Bool, completion: @escaping (Result<String, SecureT2UError>) -> Void) {
        // If online use certificate that was returned when login was created. See scram credentials property https://api.kisi.io/docs#/operations/createLogin.
        // If offline you need to fetch a short lived offline certificate for the given reader (beacon) id. See offline certificate https://api.kisi.io/docs#/operations/fetchOfflineCertificate.
    }
}

Optional

If you have opted for location permission you can also start the BeaconManager in didFinishLaunchingWithOptions

BeaconManager.shared.startMonitoring()

If you also want access to the TOTP needed for doing in-app unlocks for doors that have this feature enabled you should also start ranging in applicationWillEnterForeground.

BeaconManager.shared.startRanging()

And to avoid excessive battery consumption stop ranging in applicationDidEnterBackground.

BeaconManager.shared.stopRanging()

The beacon manager will post notifications when entering/leaving a nearby reader that you can listen for.

NotificationCenter.default.addObserver(self, selector: #selector(didEnterNotification), name: .BeaconManagerDidEnterRegionNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(didExitNotification), name: .BeaconManagerDidExitRegionNotification, object: nil)

GitHub

link
Stars: 0
Last commit: 16 hours ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Release Notes

0.1.3
16 hours ago
  • Fixed infinite loop during initialization

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics