From d781a82250d35703dc16abd42eb08a4ba1f6209a Mon Sep 17 00:00:00 2001 From: John Smith Date: Wed, 17 Nov 2021 14:21:01 +0200 Subject: [PATCH] fix "Abort Trap 6" crash (part 3 - final) --- ios/FaceTec.xcodeproj/project.pbxproj | 10 ++++++---- ios/Processors/EnrollmentProcessor.swift | 5 +++++ ios/Processors/SessionProcessingDelegate.h | 13 +++++++++--- ios/Processors/SessionProcessingDelegate.m | 8 +++++--- ios/Protocols/SessionDelegate.h | 23 ++++++++++++++++++++++ ios/Protocols/SessionDelegate.swift | 15 -------------- 6 files changed, 49 insertions(+), 25 deletions(-) create mode 100644 ios/Protocols/SessionDelegate.h delete mode 100644 ios/Protocols/SessionDelegate.swift diff --git a/ios/FaceTec.xcodeproj/project.pbxproj b/ios/FaceTec.xcodeproj/project.pbxproj index 3f1070a..e204a66 100644 --- a/ios/FaceTec.xcodeproj/project.pbxproj +++ b/ios/FaceTec.xcodeproj/project.pbxproj @@ -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 */; }; @@ -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 = ""; }; + 6848160F27452350006E55CB /* SessionDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SessionDelegate.h; sourceTree = ""; }; 6865BCCC274414FC00EF39FE /* SessionProcessingDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SessionProcessingDelegate.m; sourceTree = ""; }; 6865BCCE2744153C00EF39FE /* SessionProcessingDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SessionProcessingDelegate.h; sourceTree = ""; }; - 6865BCCF27441CC100EF39FE /* SessionDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SessionDelegate.swift; sourceTree = ""; }; 6877D1C8259BB39D00B54D84 /* UIFont+Roboto.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIFont+Roboto.swift"; sourceTree = ""; }; 6877D1CB259BC04900B54D84 /* FaceTecShadow+CSS.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FaceTecShadow+CSS.swift"; sourceTree = ""; }; 6877D1CE259BC1B900B54D84 /* CAGradientLayer+SolidFill.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CAGradientLayer+SolidFill.swift"; sourceTree = ""; }; @@ -136,7 +135,7 @@ children = ( 6878F541258BAF0F00E010B2 /* ProcesingDelegate.swift */, 68C160752590B77400843347 /* PromiseDelegate.swift */, - 6865BCCF27441CC100EF39FE /* SessionDelegate.swift */, + 6848160F27452350006E55CB /* SessionDelegate.h */, ); path = Protocols; sourceTree = ""; @@ -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; }; @@ -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; @@ -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; @@ -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; @@ -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; diff --git a/ios/Processors/EnrollmentProcessor.swift b/ios/Processors/EnrollmentProcessor.swift index 8820f33..348c723 100644 --- a/ios/Processors/EnrollmentProcessor.swift +++ b/ios/Processors/EnrollmentProcessor.swift @@ -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! @@ -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) } @@ -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: { diff --git a/ios/Processors/SessionProcessingDelegate.h b/ios/Processors/SessionProcessingDelegate.h index 6df873c..e175fef 100644 --- a/ios/Processors/SessionProcessingDelegate.h +++ b/ios/Processors/SessionProcessingDelegate.h @@ -8,13 +8,20 @@ #import #import +#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 - @property (nonatomic) id _Nonnull session; + @property (nonatomic, retain) id _Nonnull session; -- (instancetype _Nonnull ) initWithSession:(id _Nonnull)session; + // class receives a pointer to the SessionDelegate which is just + // a copy of FaceTecFaceScanProcessorDelegate +- (instancetype _Nonnull) initWithSession:(id _Nonnull)session; @end diff --git a/ios/Processors/SessionProcessingDelegate.m b/ios/Processors/SessionProcessingDelegate.m index 49dc4f4..9cc7a49 100644 --- a/ios/Processors/SessionProcessingDelegate.m +++ b/ios/Processors/SessionProcessingDelegate.m @@ -9,7 +9,7 @@ #import "SessionProcessingDelegate.h" @implementation SessionProcessingDelegate - - (instancetype) initWithSession:(id _Nonnull)session { + - (instancetype) initWithSession:(id _Nonnull)session { self = [super init]; if (self) { @@ -19,12 +19,14 @@ - (instancetype) initWithSession:(id _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 _Nonnull)sessionResult faceScanResultCallback:(id _Nonnull)faceScanResultCallback { - NSLog(@"Received face photo"); + [_session onFaceTecSessionResult:sessionResult faceScanResultCallback:faceScanResultCallback]; } @end diff --git a/ios/Protocols/SessionDelegate.h b/ios/Protocols/SessionDelegate.h new file mode 100644 index 0000000..8af397a --- /dev/null +++ b/ios/Protocols/SessionDelegate.h @@ -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 + + - (void)onFaceTecSessionResult + :(id _Nonnull) sessionResult + faceScanResultCallback :(id _Nonnull) faceScanResultCallback + NS_SWIFT_NAME(onFaceTecSessionResult(sessionResult:faceScanResultCallback:)); + + - (void)onFaceTecSessionDone NS_SWIFT_NAME(onFaceTecSessionDone()); + +@end diff --git a/ios/Protocols/SessionDelegate.swift b/ios/Protocols/SessionDelegate.swift deleted file mode 100644 index a26f37c..0000000 --- a/ios/Protocols/SessionDelegate.swift +++ /dev/null @@ -1,15 +0,0 @@ -// -// SessionDelegate.swift -// FaceTec -// -// Created by Alex Serdukov on 16.11.2021. -// Copyright © 2021 Facebook. All rights reserved. -// - -import Foundation - -@objc protocol SessionDelegate { - func onFaceTecSessionResult(sessionResult: FaceTecSessionResult, faceScanResultCallback: FaceTecFaceScanResultCallback) - - func onFaceTecSessionDone() -}