This readme will explain the necessary steps, to import Doordeck into your app.
A sample app has been provided to show how to integrate with Doordeck.
Import doordeck-sdk-swift into your project. I would suggest adding this to a separate folder, within your project.
To add dependencies via SPM, select File
> Swift Packages
> Add Package Dependency
, enter the following repo's download latest and import all associated projects
Then, to use it in your source code, add:
https://github.com/yannickl/QRCodeReader.swift.git
https://github.com/ashleymills/Reachability.swift
https://github.com/Alamofire/Alamofire
https://github.com/hyperoslo/Cache
https://github.com/jedisct1/swift-sodium
Add the following pods to your project
pod "QRCodeReader.swift", "~> 10.0"
pod "ReachabilitySwift", "~> 4.3"
pod "Alamofire", "~> 4.8"
pod "Cache", "~> 5.2"
pod "Sodium", "~> 0.8"
Add the following pods to your project
Add the following to your project plist.
“Privacy - Camera Usage Description” -> “NSCameraUsageDescription”
“Privacy - NFC Scan Usage Description” -> “NFCReaderUsageDescription”
“Privacy - Location When In Use Usage Description” -> “NSLocationAlwaysAndWhenInUseUsageDescription”
“Privacy - Location Always Usage Description” -> “NSLocationAlwaysUsageDescription"
The Camera permission is needed for the QR code reader, the NFC is needed for the NFC reader. The GPS permissions are used for GPS geofenced locks. Please make sure adequate descriptions are added to the keys, as they will be seen by the end user
In your target project go to Capabilities and enable "Near Field Communication Tag Reading", this will then enable the app for NFC.
Initialise doordeck, Doordeck expect the host app to pass an AuthToken that will be used to authenticate the user. Use AuthTokenClass when submitting an AuthToken to Doordeck. You then need to set the delegate to a class.
Please keep in mind the that you would need to provide your own token, to use the sample app, for security reasons this has not been committed into the repo.
let token = AuthTokenClass(self.token)
doordeck = Doordeck(token)
doordeck?.delegate = self
Conform to DoordeckProtocal, These methods can be used to keep the app up to date.
extension ViewController: DoordeckProtocol {
func verificationNeeded() {
print("verificationNeeded")
}
func newAuthTokenRequired() -> AuthTokenClass {
print("newAuthTokenRequired")
return AuthTokenClass(self.token)
}
func unlockSuccessful() {
print("unlockSuccessful")
}
}
We recommend that the host app first calls doordeck initialise, this will speed up the unlock process.
doordeck?.Initialize()
Unlock a door
doordeck?.showUnlockScreen(success: {
}, fail: {
})
}
Please keep in mind, Doordeck servers can reject a user and ask for permissions, if the Public key sent does not match the one on the server currently.
This is an optional step, suscribing to events will allow you to get an Enum of the events that the SDK is going through. This is helpful for both debugging problems and events collection.
place the following in viewDidAppear
NotificationCenter.default.addObserver(self, selector: #selector(self.doordeckEvents(_:)), name: SDKEvent().doordeckEventsName, object: nil)
This is the Method for the events
@objc func doordeckEvents (_ event: NSNotification) {
guard let eventAction = event.object as? SDKEvent.EventAction else {
return
}
print(eventAction)
}
Place this is in the viewDidDisappear
NotificationCenter.default.removeObserver(self, name: SDKEvent().doordeckEventsName, object: nil)