无法使用“(用户:字符串,密码:字符串)”类型的参数列表调用 'authenticate'

Cannot invoke 'authenticate' with an argument list of type '(user: String, password: String)'

我正在尝试向我正在开发的应用程序添加推荐程序。为我执行此操作的第一步是从我拥有的 phone 号码向用户发送 SMS 消息。为此,我使用的是 Twilio 和 Alamofire,但出现此错误:无法使用类型为“(用户:字符串,密码:字符串)”的参数列表调用 'authenticate'。我从我的代码中删除了我的令牌,所以它在这里(我正在导入 UIKit、Alamofire 和 Foundation):

func sendMessage() {
    if let accountSID = ProcessInfo.processInfo.environment["TWILIO_ACCOUNT_SID"],
       let authToken = ProcessInfo.processInfo.environment["TWILIO_AUTH_TOKEN"] {

      let url = "https://api.twilio.com/2010-04-01/Accounts/\(accountSID)/Messages"
      let parameters = ["From": "YOUR_TWILIO_NUMBER", "To": "YOUR_PERSONAL_NUMBER", "Body": "Hello from Swift!"]

      AF.request(url, method: .post, parameters: parameters)
        .authenticate(user: accountSID, password: authToken)
        .responseJSON { response in
          debugPrint(response)
      }

      RunLoop.main.run()
    }
}

欢迎加入。

我认为问题是,参数 accountSIDauthToken 不被视为字符串变量。

也许你应该在你的条件下施放它,就像那样:

if let accountSID = ProcessInfo.processInfo.environment["TWILIO_ACCOUNT_SID"] as? String,
       let authToken = ProcessInfo.processInfo.environment["TWILIO_AUTH_TOKEN"] as? String {

你的代码中没有任何警告吗?

您可能使用的是旧教程。 authenticate(user:password:) 在 Alamofire 5 中被重命名为 authenticate(username:password:)