Closed yogeshelevn closed 2 months ago
@phantumcode I hope you are doing well. I am writing to inform you about this issue. When I am on a call with someone, this issue arises. I hope this will help to rectify the problem. Thanks
@yogeshelevn
It seems like something in your call back is not running on the main thread
14 Runner 0x9dc8 FaceLiveDetectionController.callback(_:) + 45 (FaceLiveDetectionController.swift:45)
Can you share your code snippets and validate everything is correctly configured in your controller?
@harsh62 Thanks for writing back to me. Here is the code snippet. Please check it. I just wanted to inform you that we have created a Flutter app and then integrated this library natively. Thanks for your help; it is much appreciated.
//
// FaceLiveDetectionController.swift
// Runner
//
// Created by Yogesh on 05/12/23.
//
import Foundation
import SwiftUI
import UIKit
import FaceLiveness
class FaceLiveDetectionController: UIViewController {
var sessionId: String?
var flutterResult: FlutterResult!
var hostingController: UIHostingController<FaceLivenessDetectorView>?
override func viewDidLoad() {
super.viewDidLoad();
configureFaceDetection()
}
private func configureFaceDetection() {
if let sessionID = self.sessionId {
let faceView = FaceLivenessDetectorView(
sessionID: sessionID,
region: "ap-south-1",
disableStartView: true,
isPresented: .constant(true),
onCompletion: { result in
switch result {
case .success:
self.callback("success")
case .failure(let error):
self.callback(error.message)
}
}
)
hostingController = createHostingController(with: faceView)
addHostingControllerAsChild(hostingController!)
configureConstraints(for: hostingController!.view)
}
}
private func callback(_ res: String) {
hostingController?.dismiss(animated: true, completion: nil)
if (res == "success") {
flutterResult("success")
} else {
flutterResult(FlutterError(code: "error", message: res,details: nil))
}
}
private func createHostingController(with rootView: FaceLivenessDetectorView) -> UIHostingController<FaceLivenessDetectorView> {
return UIHostingController(rootView: rootView)
}
private func addHostingControllerAsChild(_ hostingController: UIHostingController<FaceLivenessDetectorView>) {
addChild(hostingController)
view.addSubview(hostingController.view)
}
private func configureConstraints(for view: UIView) {
view.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
view.topAnchor.constraint(equalTo: self.view.topAnchor, constant: 10),
view.bottomAnchor.constraint(equalTo: self.view.bottomAnchor),
view.leadingAnchor.constraint(equalTo: self.view.leadingAnchor),
view.trailingAnchor.constraint(equalTo: self.view.trailingAnchor)
])
}
}
Main Delegate file
import UIKit
import Flutter
import Amplify
import AWSCognitoAuthPlugin
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
do {
try Amplify.add(plugin: AWSCognitoAuthPlugin())
try Amplify.configure()
print("Amplify configured with auth plugin")
} catch {
print("Failed to initialize Amplify with \(error)")
}
let controller: FlutterViewController = window?.rootViewController as! FlutterViewController
let methodChannel = FlutterMethodChannel(name: "LIVE_VERIFICATION_CHANNEL", binaryMessenger: controller.binaryMessenger)
methodChannel.setMethodCallHandler { [weak self] (call, result) in
if call.method == "startLiveVerification" {
guard let args = call.arguments as? [String: Any],
let sessionId = args["sessionId"] as? String else {
result(FlutterError(code: "INVALID_ARGUMENT", message: "Invalid session Id",details: nil))
return
}
print("session id is \(sessionId)")
let faceLivenessController = FaceLiveDetectionController()
faceLivenessController.sessionId = sessionId
faceLivenessController.flutterResult = result
faceLivenessController.modalPresentationStyle = .fullScreen
controller.present(faceLivenessController,
animated: true,
completion: nil)
} else {
result(FlutterMethodNotImplemented)
}
}
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = self as UNUserNotificationCenterDelegate
}
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
Your onCompletion
if handling UI should run on the main thread.
onCompletion: { result in
switch result {
case .success:
self.callback("success")
case .failure(let error):
self.callback(error.message)
}
}
It should look something like this.
DispatchQueue.main.async {
switch result {
case .success:
self.callback("success")
case .failure(let error):
self.callback(error.message)
}
}
@harsh62 will check. Thanks
Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.
Describe the bug
Hi team, We are using the Amplify SDK (AmplifyUiLiveness) version 1.2.12 and Amplify version 2.29.3. We encountered a crash while performing live verification.
Steps To Reproduce
Expected behavior
App should not crash while performing verification
Swift Liveness Version
1.2.12
Xcode version
15.0.1
Relevant log output
Is this a regression?
No
Regression additional context
No response
OS Version
17.4.1
Device
iphone13
Specific to simulators
No response
Additional context
No response