Skip to content

Commit

Permalink
feat: convert code to objective-c
Browse files Browse the repository at this point in the history
  • Loading branch information
Le Hau authored and Le Hau committed Jun 1, 2022
1 parent cf490a6 commit afedf5a
Show file tree
Hide file tree
Showing 13 changed files with 213 additions and 212 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Credit Card Scanner
![npm](https://img.shields.io/npm/dm/rn-card-scanner?logo=npm)

This library provides payment card scanning functionality for your react-native app

![example.gif](example.gif)

- [Installation](#installation)
- [Usage](#usage)
- [Run example project](#run-example-project)
Expand Down
Binary file added example.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
102 changes: 31 additions & 71 deletions ios/CardScanner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
objects = {

/* Begin PBXBuildFile section */
D653FDE628435212008D6D98 /* CardScannerViewManager.m in Sources */ = {isa = PBXBuildFile; fileRef = D653FDE528435212008D6D98 /* CardScannerViewManager.m */; };
D653FDF0284355BE008D6D98 /* CardScannerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D653FDEF284355BE008D6D98 /* CardScannerView.swift */; };
D6D76838284688E300BDE508 /* CardScannerModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6D76837284688E300BDE508 /* CardScannerModule.swift */; };
D6D7683A28468B2E00BDE508 /* CardScannerModule.m in Sources */ = {isa = PBXBuildFile; fileRef = D6D7683928468B2E00BDE508 /* CardScannerModule.m */; };
D6F9145628438A8200752777 /* PayCardsRecognizer.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = D6F9145528438A8200752777 /* PayCardsRecognizer.xcframework */; };
D6D7683E2847AEDB00BDE508 /* CardScannerViewManager.m in Sources */ = {isa = PBXBuildFile; fileRef = D6D7683D2847AEDB00BDE508 /* CardScannerViewManager.m */; };
D6D768422847AF1C00BDE508 /* CardScannerView.m in Sources */ = {isa = PBXBuildFile; fileRef = D6D768412847AF1C00BDE508 /* CardScannerView.m */; };
D6D768452847B22500BDE508 /* PayCardsRecognizer.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = D6D768442847B22500BDE508 /* PayCardsRecognizer.xcframework */; };
D6D768482847B34D00BDE508 /* CardScannerModule.m in Sources */ = {isa = PBXBuildFile; fileRef = D6D768472847B34D00BDE508 /* CardScannerModule.m */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand All @@ -28,20 +27,21 @@

/* Begin PBXFileReference section */
134814201AA4EA6300B7C361 /* libCardScanner.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libCardScanner.a; sourceTree = BUILT_PRODUCTS_DIR; };
D653FDE528435212008D6D98 /* CardScannerViewManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CardScannerViewManager.m; path = CardScanner/CardScannerViewManager.m; sourceTree = "<group>"; };
D653FDEE284355BD008D6D98 /* CardScanner/CardScanner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "CardScanner/CardScanner-Bridging-Header.h"; sourceTree = "<group>"; };
D653FDEF284355BE008D6D98 /* CardScannerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = CardScannerView.swift; path = CardScanner/CardScannerView.swift; sourceTree = "<group>"; };
D6D76837284688E300BDE508 /* CardScannerModule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = CardScannerModule.swift; path = CardScanner/CardScannerModule.swift; sourceTree = "<group>"; };
D6D7683928468B2E00BDE508 /* CardScannerModule.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CardScannerModule.m; path = CardScanner/CardScannerModule.m; sourceTree = "<group>"; };
D6F9145528438A8200752777 /* PayCardsRecognizer.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = PayCardsRecognizer.xcframework; path = CardScanner/PayCardsRecognizer.xcframework; sourceTree = "<group>"; };
D6D7683D2847AEDB00BDE508 /* CardScannerViewManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CardScannerViewManager.m; path = CardScanner/CardScannerViewManager.m; sourceTree = "<group>"; };
D6D7683F2847AEEF00BDE508 /* CardScannerViewManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CardScannerViewManager.h; path = CardScanner/CardScannerViewManager.h; sourceTree = "<group>"; };
D6D768402847AEFE00BDE508 /* CardScannerView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CardScannerView.h; path = CardScanner/CardScannerView.h; sourceTree = "<group>"; };
D6D768412847AF1C00BDE508 /* CardScannerView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CardScannerView.m; path = CardScanner/CardScannerView.m; sourceTree = "<group>"; };
D6D768442847B22500BDE508 /* PayCardsRecognizer.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = PayCardsRecognizer.xcframework; path = CardScanner/PayCardsRecognizer.xcframework; sourceTree = "<group>"; };
D6D768462847B33800BDE508 /* CardScannerModule.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CardScannerModule.h; path = CardScanner/CardScannerModule.h; sourceTree = "<group>"; };
D6D768472847B34D00BDE508 /* CardScannerModule.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CardScannerModule.m; path = CardScanner/CardScannerModule.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
58B511D81A9E6C8500147676 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
D6F9145628438A8200752777 /* PayCardsRecognizer.xcframework in Frameworks */,
D6D768452847B22500BDE508 /* PayCardsRecognizer.xcframework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -59,28 +59,29 @@
58B511D21A9E6C8500147676 = {
isa = PBXGroup;
children = (
D653FDE8284352BF008D6D98 /* CardScanner */,
D6D7683C2847AEC600BDE508 /* CardScanner */,
134814211AA4EA7D00B7C361 /* Products */,
D6F9145428438A8200752777 /* Frameworks */,
D6D768432847B22500BDE508 /* Frameworks */,
);
sourceTree = "<group>";
};
D653FDE8284352BF008D6D98 /* CardScanner */ = {
D6D7683C2847AEC600BDE508 /* CardScanner */ = {
isa = PBXGroup;
children = (
D653FDE528435212008D6D98 /* CardScannerViewManager.m */,
D653FDEF284355BE008D6D98 /* CardScannerView.swift */,
D653FDEE284355BD008D6D98 /* CardScanner/CardScanner-Bridging-Header.h */,
D6D76837284688E300BDE508 /* CardScannerModule.swift */,
D6D7683928468B2E00BDE508 /* CardScannerModule.m */,
D6D7683D2847AEDB00BDE508 /* CardScannerViewManager.m */,
D6D7683F2847AEEF00BDE508 /* CardScannerViewManager.h */,
D6D768402847AEFE00BDE508 /* CardScannerView.h */,
D6D768412847AF1C00BDE508 /* CardScannerView.m */,
D6D768462847B33800BDE508 /* CardScannerModule.h */,
D6D768472847B34D00BDE508 /* CardScannerModule.m */,
);
name = CardScanner;
sourceTree = "<group>";
};
D6F9145428438A8200752777 /* Frameworks */ = {
D6D768432847B22500BDE508 /* Frameworks */ = {
isa = PBXGroup;
children = (
D6F9145528438A8200752777 /* PayCardsRecognizer.xcframework */,
D6D768442847B22500BDE508 /* PayCardsRecognizer.xcframework */,
);
name = Frameworks;
sourceTree = "<group>";
Expand Down Expand Up @@ -116,7 +117,6 @@
TargetAttributes = {
58B511DA1A9E6C8500147676 = {
CreatedOnToolsVersion = 6.1.1;
LastSwiftMigration = 1330;
};
};
};
Expand All @@ -143,10 +143,9 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
D6D7683A28468B2E00BDE508 /* CardScannerModule.m in Sources */,
D653FDE628435212008D6D98 /* CardScannerViewManager.m in Sources */,
D6D76838284688E300BDE508 /* CardScannerModule.swift in Sources */,
D653FDF0284355BE008D6D98 /* CardScannerView.swift in Sources */,
D6D768482847B34D00BDE508 /* CardScannerModule.m in Sources */,
D6D7683E2847AEDB00BDE508 /* CardScannerViewManager.m in Sources */,
D6D768422847AF1C00BDE508 /* CardScannerView.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -165,14 +164,12 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand All @@ -181,7 +178,6 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
Expand Down Expand Up @@ -218,23 +214,20 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
COPY_PHASE_STRIP = YES;
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
Expand All @@ -255,65 +248,32 @@
58B511F01A9E6C8500147676 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_TESTABILITY = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(PROJECT_DIR)",
"$(inherited)",
"$(PROJECT_DIR)/CardScanner",
);
HEADER_SEARCH_PATHS = (
"$(inherited)",
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
"$(SRCROOT)/../node_modules/react-native/React/**",
"$(SRCROOT)/../../react-native/React/**",
"$(SRCROOT)/../../../React/**",
"$(SRCROOT)/../../react-native/React/**",
);
LIBRARY_SEARCH_PATHS = (
"$(PROJECT_DIR)/CardScanner",
"$(inherited)",
"$(PROJECT_DIR)/CardScanner",
);
ONLY_ACTIVE_ARCH = YES;
LIBRARY_SEARCH_PATHS = "$(inherited)";
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = CardScanner;
SKIP_INSTALL = YES;
SWIFT_OBJC_BRIDGING_HEADER = "CardScanner-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
USER_HEADER_SEARCH_PATHS = "";
};
name = Debug;
};
58B511F11A9E6C8500147676 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_TESTABILITY = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(PROJECT_DIR)",
"$(inherited)",
"$(PROJECT_DIR)/CardScanner",
);
HEADER_SEARCH_PATHS = (
"$(inherited)",
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
"$(SRCROOT)/../node_modules/react-native/React/**",
"$(SRCROOT)/../../react-native/React/**",
"$(SRCROOT)/../../../React/**",
"$(SRCROOT)/../../react-native/React/**",
);
LIBRARY_SEARCH_PATHS = (
"$(PROJECT_DIR)/CardScanner",
"$(inherited)",
"$(PROJECT_DIR)/CardScanner",
);
ONLY_ACTIVE_ARCH = NO;
LIBRARY_SEARCH_PATHS = "$(inherited)";
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = CardScanner;
SKIP_INSTALL = YES;
SWIFT_OBJC_BRIDGING_HEADER = "CardScanner-Bridging-Header.h";
SWIFT_VERSION = 5.0;
USER_HEADER_SEARCH_PATHS = "";
};
name = Release;
};
Expand Down
13 changes: 0 additions & 13 deletions ios/CardScanner/CardScanner-Bridging-Header.h

This file was deleted.

13 changes: 13 additions & 0 deletions ios/CardScanner/CardScannerModule.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// CardScannerModule.h
// CardScanner
//
// Created by Howl on 01/06/2022.
// Copyright © 2022 Facebook. All rights reserved.
//

#import <React/RCTBridgeModule.h>

@interface CardScanner : NSObject <RCTBridgeModule>

@end
33 changes: 28 additions & 5 deletions ios/CardScanner/CardScannerModule.m
Original file line number Diff line number Diff line change
@@ -1,16 +1,39 @@
//
// CardScannerModule.m
// CardScanner
//
// Created by Howl on 01/06/2022.
// Copyright © 2022 Facebook. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "RCTBridgeModule.h"
#import "CardScannerModule.h"
#import "AVFoundation/AVFoundation.h"

@interface RCT_EXTERN_MODULE(CardScanner, NSObject)
@implementation CardScanner

RCT_EXTERN_METHOD(requestPermission: (RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
RCT_EXPORT_MODULE(CardScanner);

RCT_EXPORT_METHOD(requestPermission:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
{
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if(authStatus == AVAuthorizationStatusNotDetermined)
{
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
if(granted){
resolve(@{@"status": @"granted"});
} else {
resolve(@{@"status": @"blocked"});
}
}];
}
else if(authStatus == AVAuthorizationStatusDenied)
{
resolve(@{@"status": @"blocked"});
}
else
{
resolve(@{@"status": @"granted"});
}
}

@end
40 changes: 0 additions & 40 deletions ios/CardScanner/CardScannerModule.swift

This file was deleted.

29 changes: 29 additions & 0 deletions ios/CardScanner/CardScannerView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// CardScannerView.h
// CardScanner
//
// Created by Howl on 01/06/2022.
// Copyright © 2022 Facebook. All rights reserved.
//

#import <React/RCTView.h>
#import "UIKit/UIKit.h"
#import "UIView+React.h"
#import "PayCardsRecognizer/PayCardsRecognizer.h"

@interface CardScannerView : UIView<PayCardsRecognizerPlatformDelegate>

@property (nonatomic, weak) id<PayCardsRecognizerPlatformDelegate> delegate;

@property (nonatomic, strong) PayCardsRecognizer *recognizer;

@property (nonatomic, assign) UIColor *frameColor;

@property (nonatomic, copy) RCTBubblingEventBlock onDidScanCard;

- (void)toggleFlash;

- (void)resetResult;

@end

Loading

0 comments on commit afedf5a

Please sign in to comment.