Sinch Sms Verification 2.0.3 SDK Swift 3

走远了吗. 提交于 2019-12-11 07:58:59

问题


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!


回答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);
}


来源:https://stackoverflow.com/questions/41120985/sinch-sms-verification-2-0-3-sdk-swift-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!