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

update(26879): showing sim card missing error on sample app #6

Merged
merged 2 commits into from
Sep 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import UIKit
import TwilioVerifySNA
import CoreTelephony

final class PhoneNumberViewController: UIViewController {

Expand Down Expand Up @@ -79,6 +80,18 @@ final class PhoneNumberViewController: UIViewController {
return
}

/*
Recommended: validate if the user does have a working sim card
*/
guard hasCellularCoverage() else {
/*
Let's notify the user that the sim card is missing.
For real world use cases you probably would use a secondary verification method instead of showing an error.
*/
showGenericError("For silent network authentication, you will need a working sim card.")
return
}

// Shows the loader
toggleLoader()

Expand Down Expand Up @@ -372,4 +385,16 @@ extension PhoneNumberViewController {
forKey: KeysForUserDefaults.backendUrl.rawValue
)
}

/// Not required for the SDK implementation.
private func hasCellularCoverage() -> Bool {
let networkInfo = CTTelephonyNetworkInfo()
mejiagarcia marked this conversation as resolved.
Show resolved Hide resolved
let carriers = networkInfo.serviceSubscriberCellularProviders ?? [:]

let validCarriers = carriers.values.compactMap {
$0.isoCountryCode
}

return !validCarriers.isEmpty
}
}