i want to phone number verify my app project.Twilio documantation include UIKit but not include swiftui example,And i m try Swiftui framework but not couldn’t create button action.
import UIKit
class StartVerificationViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
@IBOutlet weak var countryCodeField: UITextField!
@IBOutlet weak var phoneNumberField: UITextField!
@IBAction func sendVerification(_ sender: Any) {
// send verification SMS
if let phoneNumber = phoneNumberField.text, let countryCode = countryCodeField.text {
VerifyAPI.sendVerificationCode(countryCode, phoneNumber)
}
}
}
*** VerifyApi is here
import Foundation
import SwiftUI
struct VerifyAPI {
static func sendVerificationCode(_ countryCode: String,
_ phoneNumber: String) {
let parameters = [
"via": "sms",
"country_code": countryCode,
"phone_number": phoneNumber
]
RequestHelper.createRequest("start", parameters) {
json in
return .success(DataResult(data: json))
}
}
}
2
Answers
This is something that I followed.
You can directly use
UIViewController
to swiftUI.example: