Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trouble when starting a Livenesscheck at IOS 18 #188

Closed
francisco-sanabria-itti opened this issue Jan 2, 2025 · 3 comments
Closed

Trouble when starting a Livenesscheck at IOS 18 #188

francisco-sanabria-itti opened this issue Jan 2, 2025 · 3 comments
Labels
pending-maintainer-response Issue is pending response from an Amplify team member question Further information is requested

Comments

@francisco-sanabria-itti
Copy link

Describe the bug

When executing the liveness feature in AWS Amplify, the process fails with an "An unknown error occurred" message. This occurs consistently and prevents further execution of the feature. There is no detailed error information provided in the logs, making it challenging to identify the root cause.

Steps To Reproduce

This is my code:

//App delegate 
import UIKit
import Flutter
import Amplify
import AWSCognitoAuthPlugin

@main
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    
      // Flutter Method Channel Setup
      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)
          }
      }

      // Notification Center (if needed)
      if #available(iOS 10.0, *) {
          UNUserNotificationCenter.current().delegate = self as UNUserNotificationCenterDelegate
      }

      // Register generated plugins
      GeneratedPluginRegistrant.register(with: self)

      return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}

// Liveness controller

import FaceLiveness
import Foundation
import SwiftUI
import UIKit

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: "<SESSION_ID>",
                credentialsProvider: MyCredentialsProvider(),
                region: "<REGION>",
                isPresented: .constant(true),
                onCompletion: { result in
                    DispatchQueue.main.async {
                        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),
        ])
    }
}

//My credentials Provider

import AWSPluginsCore
import Amplify

struct MyTemporaryCredentials: AWSTemporaryCredentials {
    let accessKeyId: String
    let secretAccessKey: String
    let sessionToken: String
    let expiration: Date
}

struct MyCredentialsProvider: AWSCredentialsProvider {
    func fetchAWSCredentials() async throws -> AWSCredentials {
        // Aquí simulas la obtención de credenciales
        return MyTemporaryCredentials(
            accessKeyId: "<ACCESS_KEY_HERE>",
            secretAccessKey: "<SECRET_ACCESS_KEY>",
            sessionToken: "",
            expiration: Date().addingTimeInterval(100000) // 1 hora de validez
        )
    }
}

I started application and the camera was open, then when I started liveness check, camera finished and the logs register this: 

Error creating the CFMessagePort needed to communicate with PPT.
Connection 1: received failure notification
flutter: Error in starting live verification: An unknown error occurred.

Expected behavior

Finish process successfuly.

Swift Liveness Version

2.42.1

Xcode version

16.2 (16C5032a)

Relevant log output

<details>
<summary>Log Messages</summary>

Error creating the CFMessagePort needed to communicate with PPT.
Connection 1: received failure notification
flutter: Error in starting live verification: An unknown error occurred.

</details>

Is this a regression?

No

Regression additional context

No response

OS Version

iOS 18.2 / MacOS 15.2

Device

IPhone 14

Specific to simulators

No response

Additional context

No response

@github-actions github-actions bot added pending-triage Issue is pending triage pending-maintainer-response Issue is pending response from an Amplify team member labels Jan 2, 2025
@sebaland
Copy link
Member

sebaland commented Jan 2, 2025

Hi @francisco-sanabria-itti, thanks for reaching out.
We've seen this error happening when you provide temporary credentials but use the AWSCredentialsProvider protocol instead of AWSTemporaryCredentials.
Based on your code snippet, that seems to be the case, as you should provide MyTemporaryCredentials() to the FaceLivenessDetectorView initializer.

EDIT: I misread your code and I now see you are indeed providing MyTemporaryCredentials. But are you correctly populating all of its fields? It seems you are leaving the sessionToken as an empty string.
If you are actually providing static credentials, then you should make MyTemporaryCredentials conform to AWSCredentials instead.

If this is not the root cause of your issue, please enable verbose logging and share them with us, as they might provide additional helpful information. You can enable verbose loggings by doing the following before calling Amplify.configure():

Amplify.Logging.logLevel = .verbose

@github-actions github-actions bot removed the pending-maintainer-response Issue is pending response from an Amplify team member label Jan 2, 2025
@sebaland sebaland added question Further information is requested pending-community-response Issue is pending response from the issue requestor and removed pending-triage Issue is pending triage labels Jan 2, 2025
@francisco-sanabria-itti
Copy link
Author

Thank you so much! It solved my problem!! ❤️

@github-actions github-actions bot added pending-maintainer-response Issue is pending response from an Amplify team member and removed pending-community-response Issue is pending response from the issue requestor labels Jan 2, 2025
Copy link

github-actions bot commented Jan 2, 2025

⚠️COMMENT VISIBILITY WARNING⚠️

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending-maintainer-response Issue is pending response from an Amplify team member question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants