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

Download and compile model function fix #208

Merged
merged 2 commits into from
Aug 18, 2020
Merged
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
9 changes: 6 additions & 3 deletions CardScan/Classes/API.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import Foundation
import CoreML

public struct Api {

Expand Down Expand Up @@ -135,20 +136,22 @@ public struct Api {
apiCall(endpoint: endpoint, parameters: apiParameters, completion: completion)
}

static public func donwloadLatestModel(signedUrl: String, completion: @escaping ApiCompletion) {
@available(iOS 11.0, *)
static public func downloadAndCompileLatestModel(signedUrl: String, completion: @escaping ApiCompletion) {
guard let url = URL(string: signedUrl) else {
DispatchQueue.main.async { completion(nil, apiUrlNotSet) }
return
}

let session = URLSession(configuration: configuration())
session.downloadTask(with: url) { (location: URL?, response: URLResponse?, error: Error?) in
guard let location = location else {
guard let location = location, let compiledUrl = try? MLModel.compileModel(at: location) else {
DispatchQueue.main.async { completion(nil, defaultError) }
return
}

DispatchQueue.main.async {
completion(["mlmodel_url": location], nil)
completion(["compiled_model_url": compiledUrl], nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will changing this break any existing code? I couldn't find anything referencing this string, is it used anywhere?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function is used in model updates in cardverify

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, so there will be a corresponding change in CardVerify here? makes sense, although this is breaking. Do we have any way of indicating which versions of CardVerify are compatible with which versions of CardScan?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes that is correct. We indicate compatibility in the cardverify podspec file, where cardverify's version dependency of cardscan is stated.

}
}.resume()
}
Expand Down