Skip to content

Commit

Permalink
feat: ios file paths fix
Browse files Browse the repository at this point in the history
  • Loading branch information
JNdhlovu committed Oct 2, 2024
1 parent b15d0a8 commit ce73792
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ internal class SmileIDDocumentCaptureView private constructor(
val showInstructions = args["showInstructions"] as? Boolean ?: true
val showAttribution = args["showAttribution"] as? Boolean ?: true
val allowGalleryUpload = args["allowGalleryUpload"] as? Boolean ?: false
val showConfirmationDialog = args["showConfirmationDialog"] as? Boolean ?: true
val idAspectRatio = (args["idAspectRatio"] as Double?)?.toFloat()
RenderDocumentCaptureScreen(
jobId = randomJobId(),
isDocumentFrontSide = isDocumentFrontSide,
showInstructions = showInstructions,
showAttribution = showAttribution,
allowGalleryUpload = allowGalleryUpload,
showConfirmationDialog = showConfirmationDialog,
idAspectRatio = idAspectRatio,
)
}
Expand All @@ -78,6 +80,7 @@ internal class SmileIDDocumentCaptureView private constructor(
showInstructions: Boolean,
showAttribution: Boolean,
allowGalleryUpload: Boolean,
showConfirmationDialog: Boolean,
idAspectRatio: Float?,
) {
val hero =
Expand Down Expand Up @@ -113,6 +116,7 @@ internal class SmileIDDocumentCaptureView private constructor(
allowGallerySelection = allowGalleryUpload,
showSkipButton = false,
instructionsHeroImage = hero,
showConfirmation = showConfirmationDialog,
instructionsTitleText = stringResource(instructionTitle),
instructionsSubtitleText = stringResource(instructionSubTitle),
captureTitleText = stringResource(captureTitleText),
Expand Down
6 changes: 5 additions & 1 deletion example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
0E26DE9A4BBFAB70477FC199 /* Pods_RunnerTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DAC1B1019A4344403D288225 /* Pods_RunnerTests.framework */; };
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; };
1E00B1732CAD9CCB005AF69D /* smile_config.json in Resources */ = {isa = PBXBuildFile; fileRef = 1E00B1722CAD9CCB005AF69D /* smile_config.json */; };
331C808B294A63AB00263BE5 /* RunnerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 331C807B294A618700263BE5 /* RunnerTests.swift */; };
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
5B80C33C8AA5AEC1DEEE0454 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 61B805DA5C7C6EBD647CDE99 /* Pods_Runner.framework */; };
Expand Down Expand Up @@ -45,6 +46,7 @@
14946750E16A70C02E2F3C34 /* Pods-RunnerTests.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.profile.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.profile.xcconfig"; sourceTree = "<group>"; };
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; };
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
1E00B1722CAD9CCB005AF69D /* smile_config.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = smile_config.json; sourceTree = "<group>"; };
331C807B294A618700263BE5 /* RunnerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RunnerTests.swift; sourceTree = "<group>"; };
331C8081294A63A400263BE5 /* RunnerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RunnerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -131,6 +133,7 @@
97C146E51CF9000F007C117D = {
isa = PBXGroup;
children = (
1E00B1722CAD9CCB005AF69D /* smile_config.json */,
9740EEB11CF90186004384FC /* Flutter */,
97C146F01CF9000F007C117D /* Runner */,
97C146EF1CF9000F007C117D /* Products */,
Expand Down Expand Up @@ -215,7 +218,7 @@
isa = PBXProject;
attributes = {
BuildIndependentTargetsInParallel = YES;
LastUpgradeCheck = 1300;
LastUpgradeCheck = 1430;
ORGANIZATIONNAME = "";
TargetAttributes = {
331C8080294A63A400263BE5 = {
Expand Down Expand Up @@ -259,6 +262,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
1E00B1732CAD9CCB005AF69D /* smile_config.json in Resources */,
97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */,
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */,
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1300"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
9 changes: 5 additions & 4 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,10 @@ class MainContent extends StatelessWidget {
MaterialPageRoute<void>(
builder: (BuildContext context) => MyScaffold(
body: SmileIDSmartSelfieCaptureView(
showConfirmationDialog: true,
showConfirmationDialog: false,
showInstructions: true,
showAttribution: false,
allowAgentMode: true,
allowAgentMode: false,
onSuccess: (String? result) {
// Your success handling logic
Map<String, dynamic> jsonResult = json.decode(result ?? '{}');
Expand Down Expand Up @@ -319,10 +319,11 @@ class MainContent extends StatelessWidget {
MaterialPageRoute<void>(
builder: (BuildContext context) => MyScaffold(
body: SmileIDDocumentCaptureView(
isDocumentFrontSide: true,
isDocumentFrontSide: false,
showConfirmationDialog: true,
showInstructions: true,
showAttribution: false,
allowGalleryUpload: true,
allowGalleryUpload: false,
onSuccess: (String? result) {
// Your success handling logic
Map<String, dynamic> jsonResult = json.decode(result ?? '{}');
Expand Down
80 changes: 32 additions & 48 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ packages:
dependency: transitive
description:
name: collection
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687
url: "https://pub.dev"
source: hosted
version: "1.18.0"
version: "1.17.2"
cupertino_icons:
dependency: "direct main"
description:
Expand All @@ -61,10 +61,10 @@ packages:
dependency: transitive
description:
name: file
sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c"
sha256: "1b92bec4fc2a72f59a8e15af5f52cd441e4a7860b49499d69dfa817af20e925d"
url: "https://pub.dev"
source: hosted
version: "7.0.0"
version: "6.1.4"
flutter:
dependency: "direct main"
description: flutter
Expand Down Expand Up @@ -98,30 +98,14 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
leak_tracker:
js:
dependency: transitive
description:
name: leak_tracker
sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05"
name: js
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
url: "https://pub.dev"
source: hosted
version: "10.0.5"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806"
url: "https://pub.dev"
source: hosted
version: "3.0.5"
leak_tracker_testing:
dependency: transitive
description:
name: leak_tracker_testing
sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3"
url: "https://pub.dev"
source: hosted
version: "3.0.1"
version: "0.6.7"
lints:
dependency: transitive
description:
Expand All @@ -134,42 +118,42 @@ packages:
dependency: transitive
description:
name: matcher
sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb
sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e"
url: "https://pub.dev"
source: hosted
version: "0.12.16+1"
version: "0.12.16"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
url: "https://pub.dev"
source: hosted
version: "0.11.1"
version: "0.5.0"
meta:
dependency: transitive
description:
name: meta
sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
url: "https://pub.dev"
source: hosted
version: "1.15.0"
version: "1.9.1"
path:
dependency: transitive
description:
name: path
sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af"
sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917"
url: "https://pub.dev"
source: hosted
version: "1.9.0"
version: "1.8.3"
platform:
dependency: transitive
description:
name: platform
sha256: "9b71283fc13df574056616011fb138fd3b793ea47cc509c189a6c3fa5f8a1a65"
sha256: "4a451831508d7d6ca779f7ac6e212b4023dd5a7d08a27a63da33756410e32b76"
url: "https://pub.dev"
source: hosted
version: "3.1.5"
version: "3.1.0"
plugin_platform_interface:
dependency: transitive
description:
Expand All @@ -182,10 +166,10 @@ packages:
dependency: transitive
description:
name: process
sha256: "21e54fd2faf1b5bdd5102afd25012184a6793927648ea81eea80552ac9405b32"
sha256: "53fd8db9cec1d37b0574e12f07520d582019cb6c44abf5479a01505099a34a09"
url: "https://pub.dev"
source: hosted
version: "5.0.2"
version: "4.2.4"
sky_engine:
dependency: transitive
description: flutter
Expand All @@ -210,18 +194,18 @@ packages:
dependency: transitive
description:
name: stack_trace
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
url: "https://pub.dev"
source: hosted
version: "1.11.1"
version: "1.11.0"
stream_channel:
dependency: transitive
description:
name: stream_channel
sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
url: "https://pub.dev"
source: hosted
version: "2.1.2"
version: "2.1.1"
string_scanner:
dependency: transitive
description:
Expand Down Expand Up @@ -250,10 +234,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb"
sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8"
url: "https://pub.dev"
source: hosted
version: "0.7.2"
version: "0.6.0"
vector_math:
dependency: transitive
description:
Expand All @@ -266,18 +250,18 @@ packages:
dependency: transitive
description:
name: vm_service
sha256: f652077d0bdf60abe4c1f6377448e8655008eef28f128bc023f7b5e8dfeb48fc
sha256: f3743ca475e0c9ef71df4ba15eb2d7684eecd5c8ba20a462462e4e8b561b2e11
url: "https://pub.dev"
source: hosted
version: "14.2.4"
version: "11.6.0"
webdriver:
dependency: transitive
description:
name: webdriver
sha256: "003d7da9519e1e5f329422b36c4dcdf18d7d2978d1ba099ea4e45ba490ed845e"
sha256: "3c923e918918feeb90c4c9fdf1fe39220fa4c0e8e2c0fffaded174498ef86c49"
url: "https://pub.dev"
source: hosted
version: "3.0.3"
version: "3.0.2"
sdks:
dart: ">=3.3.0 <4.0.0"
flutter: ">=3.18.0-18.0.pre.54"
dart: ">=3.0.5 <4.0.0"
flutter: ">=3.0.0"
1 change: 1 addition & 0 deletions ios/Classes/SmileIDDocumentCaptureView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ struct SmileIDDocumentRootView: View {
),
captureTitleText: SmileIDResourcesHelper.localizedString(for: "Action.TakePhoto"),
knownIdAspectRatio: idAspectRatio,
showConfirmation:showConfirmationDialog,
onConfirm: onConfirmed,
onError: didError,
onSkip: onSkip
Expand Down
45 changes: 42 additions & 3 deletions ios/Classes/SmileIDSmartSelfieCaptureView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ struct SmileIDRootView: View {
let allowAgentMode: Bool
let showAttribution: Bool
let channel: FlutterMethodChannel
static let shared = FileManager()
private let fileManager = Foundation.FileManager.default

var body: some View {
NavigationView {
Expand Down Expand Up @@ -129,11 +131,12 @@ struct SmileIDRootView: View {
}

extension SmileIDRootView: SmartSelfieResultDelegate {

func didSucceed(selfieImage: URL, livenessImages: [URL], apiResponse: SmartSelfieResponse?) {
// self.childViewController.removeFromParent()
// self.childViewController.removeFromParent()
var arguments: [String: Any] = [
"selfieFile": selfieImage.absoluteString,
"livenessFiles": livenessImages.map { $0.absoluteString }
"selfieFile": getFilePath(fileName: selfieImage.absoluteString),
"livenessFiles": livenessImages.map { getFilePath(fileName: $0.absoluteString) }
]
if let apiResponse = apiResponse {
let encoder = JSONEncoder()
Expand All @@ -156,6 +159,42 @@ extension SmileIDRootView: SmartSelfieResultDelegate {
func didError(error: Error) {
channel.invokeMethod("onError", arguments: error.localizedDescription)
}

func getSmileIDDirectory() -> String? {
guard let documentsDirectory = fileManager.urls(for: .documentDirectory, in: .userDomainMask).first else {
print("Unable to access documents directory")
return nil
}

let smileIDDirectory = documentsDirectory.appendingPathComponent("SmileID")
return smileIDDirectory.absoluteURL.absoluteString
}

func createSmileIDDirectoryIfNeeded() -> Bool {
guard let smileIDDirectory = getSmileIDDirectory() else {
return false
}

if !fileManager.fileExists(atPath: smileIDDirectory) {
do {
try fileManager.createDirectory(atPath: smileIDDirectory, withIntermediateDirectories: true, attributes: nil)
return true
} catch {
print("Error creating SmileID directory: \(error)")
return false
}
}

return true
}

func getFilePath(fileName: String) -> String? {
guard let smileIDDirectory = getSmileIDDirectory() else {
return nil
}

return (smileIDDirectory as NSString).appendingPathComponent(fileName)
}
}

// MARK: - Factory
Expand Down
2 changes: 2 additions & 0 deletions lib/smile_id_document_capture_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class SmileIDDocumentCaptureView extends StatelessWidget {
bool showInstructions = true,
bool showAttribution = true,
bool allowGalleryUpload = true,
bool showConfirmationDialog = true,
double? idAspectRatio,
required Function(String resultJson) onSuccess,
required Function(String errorMessage) onError,
Expand All @@ -37,6 +38,7 @@ class SmileIDDocumentCaptureView extends StatelessWidget {
"showInstructions": showInstructions,
"showAttribution": showAttribution,
"allowGalleryUpload": allowGalleryUpload,
"showConfirmationDialog": showConfirmationDialog,
"idAspectRatio": idAspectRatio,
},
);
Expand Down

0 comments on commit ce73792

Please sign in to comment.