1

Hi Im using Sinch sms verification to sign up users in my app but after updating my code to swift 3 (and sinch sdk currently 2.0.3), Im getting the following error

Use of unresolved identifier 'SINPhoneNumberUtil'

Use of unresolved identifier 'SINPhoneNumberFormat'

Use of undeclared type 'SINPhoneNumber'

That the code who was working with previous SDK and Swift 2

if (result.success){

                    let phoneUtil = SINPhoneNumberUtil() 

                    do {
                        let defaultRegion = DeviceRegion.currentCountryCode()
                        let phoneNum: SINPhoneNumber = try phoneUtil.parse(self.phoneNumber.text!, defaultRegion: defaultRegion)
                        let formattedString: String = try phoneUtil.formatNumber(phoneNum, format: SINPhoneNumberFormat.E164)//format(phoneNumber, numberFormat: .E164)
                        self.formattedNumToPass = formattedString
                        print(formattedString)
                    }
                    catch let error as NSError {
                        print(error.localizedDescription)
                    }
                    self.performSegue(withIdentifier: "enterPin", sender: sender);
}

I saw there were some changes in the SinchVerification reference docs : http://download.sinch.com/docs/verification/ios/latest/reference-swift/html/index.html
but so far I didnt succeed to make the right changes..

Thanks for your help!

ykorach
  • 588
  • 6
  • 14

1 Answers1

1

As I read in the link you attached in your question

SIN prefix was dropped so to fix the errors that you're facing just remove it from your code like this.

if (result.success) {

    let phoneUtil = SharedPhoneNumberUtil()

    do {
        let defaultRegion = DeviceRegion.currentCountryCode()
        let phoneNum: PhoneNumber =
            try phoneUtil.parse(self.phoneNumber.text!, defaultRegion: defaultRegion)
        let formattedString: String =
            try phoneUtil.formatNumber(phoneNum, format: PhoneNumberFormat.e164) //format(phoneNumber, numberFormat: .E164)
        self.formattedNumToPass = formattedString
        print(formattedString)
    } catch
    let error as NSError {
        print(error.localizedDescription)
    }
    self.performSegue(withIdentifier: "enterPin", sender: sender);
}
jerem
  • 1,016
  • 2
  • 12
  • 27
zombie
  • 5,069
  • 3
  • 25
  • 54
  • I already try that but Im getting the following error : 'PhoneNumberUtil' cannot be constructed because it has no accessible initializers – jerem Dec 13 '16 at 13:35
  • you can get it throw the shared function as it is mentioned in: http://download.sinch.com/docs/verification/ios/latest/reference-swift/html/Functions.html#/s:F17SinchVerification21SharedPhoneNumberUtilFT_PS_15PhoneNumberUtil_ – zombie Dec 13 '16 at 13:54