From 5350c30a25779f8514e3e4cc2496411844129511 Mon Sep 17 00:00:00 2001 From: Andrea Franz Date: Wed, 25 Nov 2020 10:24:35 +0100 Subject: [PATCH] add base keycard methods --- ios/StatusKeycard.m | 2 + ios/StatusKeycard.swift | 53 +++++++++++++++++++++ ios/StatusKeycard.xcodeproj/project.pbxproj | 14 +++--- react-native-status-keycard.podspec | 4 +- 4 files changed, 64 insertions(+), 9 deletions(-) diff --git a/ios/StatusKeycard.m b/ios/StatusKeycard.m index b0ae4ef..b0c7bec 100644 --- a/ios/StatusKeycard.m +++ b/ios/StatusKeycard.m @@ -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 diff --git a/ios/StatusKeycard.swift b/ios/StatusKeycard.swift index 5e5742d..194116e 100644 --- a/ios/StatusKeycard.swift +++ b/ios/StatusKeycard.swift @@ -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 + } } diff --git a/ios/StatusKeycard.xcodeproj/project.pbxproj b/ios/StatusKeycard.xcodeproj/project.pbxproj index 6e0aa23..2fe4d89 100644 --- a/ios/StatusKeycard.xcodeproj/project.pbxproj +++ b/ios/StatusKeycard.xcodeproj/project.pbxproj @@ -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 */ diff --git a/react-native-status-keycard.podspec b/react-native-status-keycard.podspec index 3fa42f5..a4a3b0d 100644 --- a/react-native-status-keycard.podspec +++ b/react-native-status-keycard.podspec @@ -13,9 +13,9 @@ Pod::Spec.new do |s| s.platforms = { :ios => "9.0" } s.source = { :git => "https://github.com/status-im/react-native-status-keycard.git", :tag => "#{s.version}" } - + s.source_files = "ios/**/*.{h,m,mm,swift}" - + s.dependency "React" end