-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
365 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleDevelopmentRegion</key> | ||
<string>$(DEVELOPMENT_LANGUAGE)</string> | ||
<key>CFBundleExecutable</key> | ||
<string>$(EXECUTABLE_NAME)</string> | ||
<key>CFBundleIdentifier</key> | ||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundleName</key> | ||
<string>$(PRODUCT_NAME)</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>1.0</string> | ||
<key>CFBundleVersion</key> | ||
<string>1</string> | ||
<key>NSBluetoothAlwaysUsageDescription</key> | ||
<string>Secure transmission of mobile DL data</string> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import CoreBluetooth | ||
import SpruceIDWalletSdkRs | ||
|
||
public class MDocReader { | ||
var sessionManager: MdlSessionManager | ||
var bleManager: MDocReaderBLEPeripheral! | ||
var callback: BLEReaderSessionStateDelegate | ||
|
||
public init?(callback: BLEReaderSessionStateDelegate, uri: String, requestedItems: [String: [String: Bool]]) { | ||
self.callback = callback | ||
do { | ||
let sessionData = try SpruceIDWalletSdkRs.establishSession(uri: uri, requestedItems: requestedItems, trustAnchorRegistry: nil) | ||
self.sessionManager = sessionData.state | ||
self.bleManager = MDocReaderBLEPeripheral(callback: self, serviceUuid: CBUUID(string: sessionData.uuid), request: sessionData.request, bleIdent: Data(sessionData.bleIdent.utf8)) | ||
} catch { | ||
print("\(error)") | ||
return nil | ||
} | ||
} | ||
|
||
public func cancel() { | ||
bleManager.disconnect() | ||
} | ||
} | ||
|
||
extension MDocReader: MDocReaderBLEDelegate { | ||
func callback(message: MDocReaderBLECallback) { | ||
switch message { | ||
case .done(let data): | ||
self.callback.update(state: .success(data)) | ||
case .connected: | ||
self.callback.update(state: .connected) | ||
case .error(let error): | ||
self.callback.update(state: .error(BleReaderSessionError(readerBleError: error))) | ||
self.cancel() | ||
case .message(let data): | ||
do { | ||
let responseData = try SpruceIDWalletSdkRs.handleResponse(state: self.sessionManager, response: data) | ||
self.sessionManager = responseData.state | ||
self.callback.update(state: .success(responseData.verifiedResponse)) | ||
} catch { | ||
self.callback.update(state: .error(.generic("\(error)"))) | ||
self.cancel() | ||
} | ||
case .downloadProgress(let index): | ||
self.callback.update(state: .downloadProgress(index)) | ||
} | ||
} | ||
} | ||
|
||
/// To be implemented by the consumer to update the UI | ||
public protocol BLEReaderSessionStateDelegate: AnyObject { | ||
func update(state: BLEReaderSessionState) | ||
} | ||
|
||
public enum BLEReaderSessionState { | ||
/// App should display the error message | ||
case error(BleReaderSessionError) | ||
/// App should indicate to the reader is waiting to connect to the holder | ||
case advertizing | ||
/// App should indicate to the user that BLE connection has been established | ||
case connected | ||
/// App should display the fact that a certain amount of data has been received | ||
/// - Parameters: | ||
/// - 0: The number of chunks received to far | ||
case downloadProgress(Int) | ||
/// App should display a success message and offer to close the page | ||
case success([String: [String: [String: MDocItem]]]) | ||
} | ||
|
||
public enum BleReaderSessionError { | ||
/// When communication with the server fails | ||
case server(String) | ||
/// When Bluetooth is unusable (e.g. unauthorized). | ||
case bluetooth(CBCentralManager) | ||
/// Generic unrecoverable error | ||
case generic(String) | ||
|
||
init(readerBleError: MdocReaderBleError) { | ||
switch readerBleError { | ||
case .server(let string): | ||
self = .server(string) | ||
case .bluetooth(let string): | ||
self = .bluetooth(string) | ||
} | ||
} | ||
} |
Oops, something went wrong.