add base keycard methods

This commit is contained in:
Andrea Franz 2020-11-25 10:24:35 +01:00
parent 8d80f25a2e
commit 5350c30a25
4 changed files with 64 additions and 9 deletions

View File

@ -5,5 +5,7 @@
RCT_EXTERN_METHOD(multiply:(float)a withB:(float)b
withResolver:(RCTPromiseResolveBlock)resolve
withRejecter:(RCTPromiseRejectBlock)reject)
RCT_EXTERN_METHOD(hasKeycardSDK:(RCTPromiseResolveBlock)resolve rejecter: (RCTPromiseRejectBlock)reject)
RCT_EXTERN_METHOD(hasNFC:(RCTPromiseResolveBlock)resolve rejecter: (RCTPromiseRejectBlock)reject)
@end

View File

@ -1,8 +1,61 @@
import Foundation
import Keycard
@objc(StatusKeycard)
class StatusKeycard: NSObject {
@available(iOS 13.0, *)
private(set) lazy var keycardController: KeycardController? = nil
@objc(multiply:withB:withResolver:withRejecter:)
func multiply(a: Float, b: Float, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void {
resolve(a*b)
}
@objc
func select() {
if #available(iOS 13.0, *) {
keycardController = KeycardController(onConnect: { [unowned self] channel in
do {
let cmdSet = KeycardCommandSet(cardChannel: channel)
let info = try ApplicationInfo(cmdSet.select().checkOK().data)
print(info)
self.keycardController?.stop(alertMessage: "Success")
} catch {
print("Error: \(error)")
self.keycardController?.stop(errorMessage: "Read error. Please try again.")
}
self.keycardController = nil
}, onFailure: { [unowned self] error in
print("Disconnected: \(error)")
self.keycardController = nil
})
keycardController?.start(alertMessage: "Hold your iPhone near a Status Keycard.")
} else {
print("Unavailable")
}
}
@objc
func hasKeycardSDK(_ resolve: RCTPromiseResolveBlock, rejecter _: RCTPromiseRejectBlock) -> Void {
if #available(iOS 13.0, *) {
resolve(true)
} else {
resolve(false)
}
}
@objc
func hasNFC(_ resolve: RCTPromiseResolveBlock, rejecter _: RCTPromiseRejectBlock) -> Void {
if #available(iOS 13.0, *) {
resolve(KeycardController.isAvailable)
} else {
resolve(false)
}
}
@objc
static func requiresMainQueueSetup() -> Bool {
return true
}
}

View File

@ -7,7 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
65B8C62E256D27DB00C6A3EE /* Keycard in Frameworks */ = {isa = PBXBuildFile; productRef = 65B8C62D256D27DB00C6A3EE /* Keycard */; };
65B8C633256D352A00C6A3EE /* Keycard in Frameworks */ = {isa = PBXBuildFile; productRef = 65B8C632256D352A00C6A3EE /* Keycard */; };
F4FF95D7245B92E800C19C63 /* StatusKeycard.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4FF95D6245B92E800C19C63 /* StatusKeycard.swift */; };
/* End PBXBuildFile section */
@ -35,7 +35,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
65B8C62E256D27DB00C6A3EE /* Keycard in Frameworks */,
65B8C633256D352A00C6A3EE /* Keycard in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -77,7 +77,7 @@
);
name = StatusKeycard;
packageProductDependencies = (
65B8C62D256D27DB00C6A3EE /* Keycard */,
65B8C632256D352A00C6A3EE /* Keycard */,
);
productName = RCTDataManager;
productReference = 134814201AA4EA6300B7C361 /* libStatusKeycard.a */;
@ -107,7 +107,7 @@
);
mainGroup = 58B511D21A9E6C8500147676;
packageReferences = (
65B8C62C256D27DB00C6A3EE /* XCRemoteSwiftPackageReference "Keycard" */,
65B8C631256D352A00C6A3EE /* XCRemoteSwiftPackageReference "Keycard" */,
);
productRefGroup = 58B511D21A9E6C8500147676;
projectDirPath = "";
@ -284,7 +284,7 @@
/* End XCConfigurationList section */
/* Begin XCRemoteSwiftPackageReference section */
65B8C62C256D27DB00C6A3EE /* XCRemoteSwiftPackageReference "Keycard" */ = {
65B8C631256D352A00C6A3EE /* XCRemoteSwiftPackageReference "Keycard" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/status-im/Keycard.swift";
requirement = {
@ -295,9 +295,9 @@
/* End XCRemoteSwiftPackageReference section */
/* Begin XCSwiftPackageProductDependency section */
65B8C62D256D27DB00C6A3EE /* Keycard */ = {
65B8C632256D352A00C6A3EE /* Keycard */ = {
isa = XCSwiftPackageProductDependency;
package = 65B8C62C256D27DB00C6A3EE /* XCRemoteSwiftPackageReference "Keycard" */;
package = 65B8C631256D352A00C6A3EE /* XCRemoteSwiftPackageReference "Keycard" */;
productName = Keycard;
};
/* End XCSwiftPackageProductDependency section */