您好我使用Sinch短信验证在我的应用程序中注册用户但在将我的代码更新为swift 3(和sinch sdk目前2.0.3)后,我收到以下错误
Cannot convert value of type '(Bool, NSError?) -> Void' to expected argument type '(Bool, Error?) -> Void'
我知道如果我将NSError更改为Error,则此错误消失
但我需要从NSError获取错误代码,以提醒我的用户发生了什么事情取决于此错误
if (result.success){
//login user
} else {
if error!.code == 6 {
let msg = NSLocalizedString("This Phone Number is invalid",
comment: "This Phone Number is invalid pop up alert")
print(msg)
}
}
来自Sinch Docs,我想要使用这个NSError:
https://www.sinch.com/docs/verification/ios/#swiftsdk
let verification = SMSVerification(applicationKey:"<APP KEY>", phoneNumber: phoneNumberInE164)
verification.initiate { (result: InitiationResult, error: NSError?) -> Void in
// handle outcome
}
有没有办法从错误中获取error.code:错误? 谢谢你的帮助
答案 0 :(得分:3)
let verification = SMSVerification(applicationKey:"<APP KEY>", phoneNumber: phoneNumberInE164)
verification.initiate { (result: InitiationResult, error: Error?) -> Void in
// handle outcome
if (result.success){
//login user
} else if let error = error as? NSError, error.code == 6 {
let msg = NSLocalizedString("This Phone Number is invalid",
comment: "This Phone Number is invalid pop up alert")
print(msg)
}
}