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

BOUNCER-1436: Fix ML model loading from wrong bundle #2142

Merged
merged 2 commits into from
Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
## X.Y.Z 2022-xx-xx
## PaymentSheet
### PaymentSheet
* [Fixed] Fixed an issue that caused animations of the card logos in the Card input field to glitch.
* [Fixed] Fixed a layout issue in the "Save my info" checkbox.

### CardScan
* [Fixed] Fixed UX model loading from the wrong bundle. [#2078](https://github.com/stripe/stripe-ios/issues/2078) (Thanks [nickm01](https://github.com/nickm01))

## 23.3.0 2022-12-05
### PaymentSheet
* [Added] Added logos of accepted card brands on Card input field.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import UIKit

@_spi(STP) public class UxAnalyzer: CreditCardOcrImplementation {
@AtomicProperty var uxModel: UxModel?

static let uxResource = "UxModel"
static let uxExtension = "mlmodelc"

let ocr: CreditCardOcrImplementation

init(
Expand All @@ -26,7 +30,7 @@ import UIKit

@_spi(STP) public static func loadModelFromBundle() -> UxModel? {
let bundle = StripeCardScanBundleLocator.resourcesBundle
guard let url = bundle.url(forResource: "UxModel", withExtension: "mlmodelc") else {
guard let url = bundle.url(forResource: UxAnalyzer.uxResource, withExtension: UxAnalyzer.uxExtension) else {
return nil
}

Expand Down Expand Up @@ -60,7 +64,16 @@ import UIKit
}

private func loadModel() {
UxModel.asyncLoad { [weak self] result in
guard
let uxModelUrl = StripeCardScanBundleLocator.resourcesBundle.url(
forResource: UxAnalyzer.uxResource,
withExtension: UxAnalyzer.uxExtension
)
else {
return
}

UxModel.asyncLoad(contentsOf: uxModelUrl) { [weak self] result in
switch result {
case .success(let model):
self?.uxModel = model
Expand Down