Skip to content

Commit

Permalink
fix "Abort Trap 6" crash (part 3 - final)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsmith-gooddollar committed Nov 17, 2021
1 parent 84c8950 commit d781a82
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 25 deletions.
10 changes: 6 additions & 4 deletions ios/FaceTec.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

/* Begin PBXBuildFile section */
6865BCCD274414FC00EF39FE /* SessionProcessingDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 6865BCCC274414FC00EF39FE /* SessionProcessingDelegate.m */; };
6865BCD027441CC200EF39FE /* SessionDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6865BCCF27441CC100EF39FE /* SessionDelegate.swift */; };
6877D1C9259BB39D00B54D84 /* UIFont+Roboto.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6877D1C8259BB39D00B54D84 /* UIFont+Roboto.swift */; };
6877D1CC259BC04900B54D84 /* FaceTecShadow+CSS.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6877D1CB259BC04900B54D84 /* FaceTecShadow+CSS.swift */; };
6877D1CF259BC1B900B54D84 /* CAGradientLayer+SolidFill.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6877D1CE259BC1B900B54D84 /* CAGradientLayer+SolidFill.swift */; };
Expand Down Expand Up @@ -46,9 +45,9 @@
/* Begin PBXFileReference section */
134814201AA4EA6300B7C361 /* libFaceTec.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libFaceTec.a; sourceTree = BUILT_PRODUCTS_DIR; };
681756B1258BAF7500177E7F /* FaceTec-Bridging-Header.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "FaceTec-Bridging-Header.h"; sourceTree = "<group>"; };
6848160F27452350006E55CB /* SessionDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SessionDelegate.h; sourceTree = "<group>"; };
6865BCCC274414FC00EF39FE /* SessionProcessingDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SessionProcessingDelegate.m; sourceTree = "<group>"; };
6865BCCE2744153C00EF39FE /* SessionProcessingDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SessionProcessingDelegate.h; sourceTree = "<group>"; };
6865BCCF27441CC100EF39FE /* SessionDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SessionDelegate.swift; sourceTree = "<group>"; };
6877D1C8259BB39D00B54D84 /* UIFont+Roboto.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIFont+Roboto.swift"; sourceTree = "<group>"; };
6877D1CB259BC04900B54D84 /* FaceTecShadow+CSS.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FaceTecShadow+CSS.swift"; sourceTree = "<group>"; };
6877D1CE259BC1B900B54D84 /* CAGradientLayer+SolidFill.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CAGradientLayer+SolidFill.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -136,7 +135,7 @@
children = (
6878F541258BAF0F00E010B2 /* ProcesingDelegate.swift */,
68C160752590B77400843347 /* PromiseDelegate.swift */,
6865BCCF27441CC100EF39FE /* SessionDelegate.swift */,
6848160F27452350006E55CB /* SessionDelegate.h */,
);
path = Protocols;
sourceTree = "<group>";
Expand Down Expand Up @@ -345,7 +344,6 @@
68B9B7292594E482007E6027 /* FaceVerification.swift in Sources */,
68B9B6F42594DA2A007E6027 /* String+SnakeCase.swift in Sources */,
68AB478C259689DA006B2E4C /* FaceVerificationError.swift in Sources */,
6865BCD027441CC200EF39FE /* SessionDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -383,6 +381,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEFINES_MODULE = YES;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
Expand Down Expand Up @@ -411,6 +410,7 @@
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
PRECOMPS_INCLUDE_HEADERS_FROM_BUILT_PRODUCTS_DIR = YES;
PRODUCT_MODULE_NAME = FaceTec;
SDKROOT = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_PRECOMPILE_BRIDGING_HEADER = NO;
Expand Down Expand Up @@ -449,6 +449,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = YES;
DEFINES_MODULE = YES;
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
Expand All @@ -469,6 +470,7 @@
);
MTL_ENABLE_DEBUG_INFO = NO;
PRECOMPS_INCLUDE_HEADERS_FROM_BUILT_PRODUCTS_DIR = YES;
PRODUCT_MODULE_NAME = FaceTec;
SDKROOT = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_PRECOMPILE_BRIDGING_HEADER = NO;
Expand Down
5 changes: 5 additions & 0 deletions ios/Processors/EnrollmentProcessor.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import AVFoundation

// implementing SessionDelegate which is the same than FaceTecFaceScanProcessorDelegate
// but causes no issues during build
class EnrollmentProcessor: NSObject, URLSessionTaskDelegate, SessionDelegate {
var maxRetries: Int?
var enrollmentIdentifier: String!
Expand Down Expand Up @@ -27,6 +29,8 @@ class EnrollmentProcessor: NSObject, URLSessionTaskDelegate, SessionDelegate {
self.presentSessionVCFrom = fromVC

super.init()
// instantiating a session delegate ObjectiveC class
// wrapping the enrollment processor
self.sessionDelegate = SessionProcessingDelegate(session: self)
}

Expand All @@ -48,6 +52,7 @@ class EnrollmentProcessor: NSObject, URLSessionTaskDelegate, SessionDelegate {
}

DispatchQueue.main.async {
// the sessionDelegate now passes to createSessionVC instead of EnrollmentProcessor
let sessionVC = FaceTec.sdk.createSessionVC(faceScanProcessorDelegate: self.sessionDelegate!, sessionToken: sessionToken)

self.presentSessionVCFrom.present(sessionVC, animated: true, completion: {
Expand Down
13 changes: 10 additions & 3 deletions ios/Processors/SessionProcessingDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,20 @@

#import <Foundation/Foundation.h>
#import <FaceTecSDK/FaceTecSDK.h>
#import "../Protocols/SessionDelegate.h"

@protocol SessionDelegate;
// due to the unknown reason compiler crashes when you're trying
// to implement FaceTecFaceScanProcessorDelegate from the Swift class
// AND building a ReactNative project. On separate iOS app everything is fine
// To workaround i had to define this ObjectiveC class and pass its instance
// to the createSessionVC()

@interface SessionProcessingDelegate : NSObject<FaceTecFaceScanProcessorDelegate>

@property (nonatomic) id<SessionDelegate> _Nonnull session;
@property (nonatomic, retain) id<SessionDelegate> _Nonnull session;

- (instancetype _Nonnull ) initWithSession:(id <SessionDelegate> _Nonnull)session;
// class receives a pointer to the SessionDelegate which is just
// a copy of FaceTecFaceScanProcessorDelegate
- (instancetype _Nonnull) initWithSession:(id <SessionDelegate> _Nonnull)session;

@end
8 changes: 5 additions & 3 deletions ios/Processors/SessionProcessingDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#import "SessionProcessingDelegate.h"

@implementation SessionProcessingDelegate
- (instancetype) initWithSession:(id <SessionDelegate> _Nonnull)session {
- (instancetype) initWithSession:(id<SessionDelegate> _Nonnull)session {
self = [super init];

if (self) {
Expand All @@ -19,12 +19,14 @@ - (instancetype) initWithSession:(id <SessionDelegate> _Nonnull)session {
return self;
}

// the wrapper class is doing nothing then implementing FaceTecFaceScanProcessorDelegate
// and proxyiong its calls to the SessionDelegate which is the EnrollmentProcessor
- (void) onFaceTecSDKCompletelyDone {
NSLog(@"Session done");
[_session onFaceTecSessionDone];
}

- (void) processSessionWhileFaceTecSDKWaits:(id<FaceTecSessionResult> _Nonnull)sessionResult faceScanResultCallback:(id<FaceTecFaceScanResultCallback> _Nonnull)faceScanResultCallback {
NSLog(@"Received face photo");
[_session onFaceTecSessionResult:sessionResult faceScanResultCallback:faceScanResultCallback];
}

@end
23 changes: 23 additions & 0 deletions ios/Protocols/SessionDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// SessionDelegate.h
// FaceTec
//
// Created by Alex Serdukov on 17.11.2021.
// Copyright © 2021 Facebook. All rights reserved.
//

// this is actually a copy of FaceTecFaceScanProcessorDelegate
// it could be defined also on Swift but there's an additional
// research is needed to understand why onFaceTecSessionResult
// doesn't exposed to the auto generated -Swift.h header
// so now it's written on Objective C too
@protocol SessionDelegate<NSObject>

- (void)onFaceTecSessionResult
:(id<FaceTecSessionResult> _Nonnull) sessionResult
faceScanResultCallback :(id<FaceTecFaceScanResultCallback> _Nonnull) faceScanResultCallback
NS_SWIFT_NAME(onFaceTecSessionResult(sessionResult:faceScanResultCallback:));

- (void)onFaceTecSessionDone NS_SWIFT_NAME(onFaceTecSessionDone());

@end
15 changes: 0 additions & 15 deletions ios/Protocols/SessionDelegate.swift

This file was deleted.

0 comments on commit d781a82

Please sign in to comment.