regulaforensics / DocumentReader-iOS

iOS Framework for reading and validation of identification documents
56 stars 15 forks source link

Auto update and initialization problems #31

Closed olcayertas closed 4 years ago

olcayertas commented 4 years ago

We are using auto update with the latest pod version of the SDK:

docReader.runAutoUpdate(databaseID: "Full", progressHandler: { progress in
    let percent = progress.completedUnitCount * 100 / progress.totalUnitCount
    HUD.show(.label("Updating database: % \(percent)"))
}, completion: { [weak self] (success, error) in
    HUD.hide()
    if success {
        self?.initDocumentReader()
    } else {
        print(error ?? "")
    }
})

Update finishes with succes but we are not able get database. Here our init code:

extension DocReader {

    func initializeReader(_ completion: @escaping DocumentReaderInitializationCompletion) {
        guard let licensePath = Bundle.main.path(forResource: "regula", ofType: "license") else {
            print("Failed to get license path")
            completion(false, "Failed to get license path")
            return
        }
        guard let databasePath = Bundle.main.path(forResource: "db", ofType: "dat") else {
            print("PassengerView : failed to get database path")
            completion(false, "Failed to get database path")
            return
        }
        do {
            let licenseData = try Data(contentsOf: URL(fileURLWithPath: licensePath))
            initializeReader(license: licenseData, databasePath: databasePath) { [completion] (successful, error) in
                completion(true, nil)
            }
        } catch let error {
            completion(false, error.localizedDescription)
            print("Failed to get license data!")
        }
    }
}

I we use Bundle.main.path(forResource: "regula.license", ofType: nil) as decribed in documents instead of Bundle.main.path(forResource: "regula", ofType: "license") it failes while getting the licence path. We both have tried Bundle.main.path(forResource: "db", ofType: "dat") and Bundle.main.path(forResource: "db.dat", ofType: nil) but both failes. We are only able to initialize reader without using databasePath:

extension DocReader {

    func initializeReader(_ completion: @escaping DocumentReaderInitializationCompletion) {
        guard let licensePath = Bundle.main.path(forResource: "regula", ofType: "license") else {
            print("Failed to get license path")
            completion(false, "Failed to get license path")
            return
        }
        do {
            let licenseData = try Data(contentsOf: URL(fileURLWithPath: licensePath))
            initializeReader(license: licenseData) { [completion] (successful, error) in
                completion(true, nil)
            }
        } catch let error {
            completion(false, error.localizedDescription)
            print("Failed to get license data!")
        }
    }
}

but after succesful auto update and document reader initialization when we restart application auto update gives this error: Error during fetching database url from Core But if we ignore this error and try to initialize document reader it works.

We have two targets for our application and only difference is their bundle identifiers. The target for test environment has test suffix:

The last working combination of auto update and initialize working for Prod but in test we only get one scenario available: Capture

Can you help us?

vyakimchik commented 4 years ago

Hello.

  1. Have you added the database (db.dat file) to the project?

    We both have tried Bundle.main.path(forResource: "db", ofType: "dat") and Bundle.main.path(forResource: "db.dat", ofType: nil) but both failes. We are only able to initialize reader without using databasePath:

  2. Could you please provide a small demo project so that we can reproduce this issue or modify our project which is available in this repository as we aren't able to reproduce this issue?

    but after succesful auto update and document reader initialization when we restart application auto update gives this error: Error during fetching database url from Core

  3. It seems that the bundle id with the test suffix is missed in the regula.license file. Therefore, it doesn't initialize.

    We have two targets for our application and only difference is their bundle identifiers. The target for test environment has test suffix:

    Prod environment bundle identifier: com.company.app Test environment bundle identifier: com.company.app.test The last working combination of auto update and initialize working for Prod but in test we only get one scenario available: Capture

olcayertas commented 4 years ago

Wo don't add database file. We are using just auto update. I will provide a sample project tomorrow.

vyakimchik commented 4 years ago

If you don't add the db.dat manually to the project, you don't need to indicate databasePath in the initializeReader function.