Closed lsamaria closed 4 years ago
Can you test with the fix_layout
branch ?
I’ll try it later tonight and get back to you.
Btw I got it to work with the Apple emoji. I just had to clean the derived data after changing the code.
I haven’t had a chance to get to it yet. I’m working on 3 apps and hoping to release them this week. Once I get them to the AppStore I’ll immediately jump on top of this.
I finally got a chance to download the new Podfile. You fixed the issue, thanks!!!
@lsamaria can you please tell me which pod version fixed ??? currently I'm suing 0.8.0 not working for me.
@venkateshwarlut This pod is no longer supported. The last commit was Dec 2019. I switched to phoneNumberKit. It's very easy to use. Let me know if you need some help setting up, I'll send some code.
@
@venkateshwarlut This pod is no longer supported. The last commit was Dec 2019. I switched to phoneNumberKit. It's very easy to use. Let me know if you need some help setting up, I'll send some code.
Yes please share me sample code. I will check and setup.
@venkateshwarlut
In checkPhoneNumberValidity()
you want to check if isNumberValid ...
then do whatever with all of the info
import PhoneNumberKit
lazy var phoneNumberTextField: PhoneNumberTextField = {
let textField = PhoneNumberTextField()
textField.translatesAutoresizingMaskIntoConstraints = false
textField.font = UIFont.systemFont(ofSize: 19)
textField.textColor = UIColor.black
textField.autocorrectionType = .no
textField.keyboardType = .phonePad
textField.layer.borderWidth = 1
textField.layer.borderColor = UIColor.black.cgColor
textField.layer.cornerRadius = 5
textField.inputAccessoryView = UIView() // hides Done button from keyboard
textField.withPrefix = true
textField.withExamplePlaceholder = true
textField.withFlag = true
textField.withDefaultPickerUI = true
textField.addTarget(self, action: #selector(checkPhoneNumberValidity), for: .editingChanged)
return textField
}()
var phoneNumberKit: PhoneNumberKit!
override func viewDidLoad() {
super.viewDidLoad()
phoneNumberKit = PhoneNumberKit()
}
deinit {
phoneNumberKit = nil
}
@objc func checkPhoneNumberValidity() {
guard let textFieldText = phoneNumberTextField.text else { return }
guard let phoneNumberKit = phoneNumberKit else { return }
do {
let phoneNumber = try phoneNumberKit.parse(textFieldText)
let numberString = phoneNumber.numberString
let countryCode = phoneNumber.countryCode
let nationalNumber = phoneNumber.nationalNumber
let numberExtension = phoneNumber.numberExtension
let type = phoneNumber.type
print("\nnumberString: \(numberString) | countryCode: \(countryCode) | nationalNumber: \(nationalNumber) | numberExtension: \(numberExtension as Any) | type: \(type)")
let formattedPhoneNumberStr = phoneNumberKit.format(phoneNumber, toType: .e164)
print("formattedPhoneNumberStr: \(formattedPhoneNumberStr)\n")
if let regionCode = phoneNumberKit.mainCountry(forCode: countryCode) {
//let country = Locale.current.localizedString(forRegionCode: regionCode)
//print("\nregionCode: \(regionCode) | country: \(country as Any)\n")
let countryCodePlusNationalNumber = String(countryCode) + String(nationalNumber)
print("countryCodePlusNationalNumber: \(countryCodePlusNationalNumber)\n")
let isNumberValid = phoneNumberKit.isValidPhoneNumber(countryCodePlusNationalNumber, withRegion: regionCode, ignoreType: true)
if isNumberValid {
print("valid phone number")
} else {
print("invalid phone number")
}
} else {
print("regionCode is nil")
}
} catch {
print("Generic parser error: ", error.localizedDescription)
}
}
For some reason when I have a programmatic collectionView and I present the vc with the
FPNTextField
class the flag doesn't appear.Another problem as you can see in the photo above, the
unknown
image in your asset catalog doesn't appear in either theFPNTextField
at the top nor theFPNCountryPicker
at the bottom. When I look into the asset folder these are the errors I see:In the FPNCountry file when the images get loaded, if an image can't be found the
unknown
image is provided as a fallback image but there isn't an alternative for theunknown
imageI tried this fix (red arrow in below pic) for the asset catalog warning but nada.
As for as the initial problem itself I don't have the problem with any other classes that present the vc with the FPNTextField because all the flags appear. All my code is programmatic so it's easy to just c+p and move the presenter code around. The problem only happens in classes with a collectionView. I narrowed it down to the constraints, for whatever reason the cv constraints in one class somehow affects the flags in another class. These are the constraints I use:
I also tried setting the cv size to
view.bounds
when I instantiate it but the same problem occurred:This problem occurs wether pushing on presenting.
To Reproduce
Create a programmatic collectionView with the same constraints I used above. Add a barButtonItem and for it's target action either push or present another vc that contains the FPNTextField
Expected behavior The flags should appear and when they don't the
unknown
image should appearScreenshots see above
Smartphone (please complete the following information): iPhone 7+ and all the simulator iPhones and iPads
FlagPhoneNumber (please complete the following information):
Additional context Add any other context about the problem here.