您好我使用Sinch短信验证在我的应用程序中注册用户但在将我的代码更新为swift 3(和sinch sdk目前2.0.3)后,我收到以下错误
使用未解析的标识符'SINPhoneNumberUtil'
使用未解析的标识符'SINPhoneNumberFormat'
使用未声明类型'SINPhoneNumber'
使用以前的SDK和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);
}
我看到SinchVerification参考文档中有一些变化:
http://download.sinch.com/docs/verification/ios/latest/reference-swift/html/index.html
但到目前为止,我没有成功做出正确的改变。
感谢您的帮助!
答案 0 :(得分:1)
当我读到您在问题中附上的链接时
SIN
前缀已被删除,以便修复您所面临的错误,只需将其从代码中删除即可。
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);
}