【问题标题】:xcode showing error - 'appendingPathComponent' is unavailable: Use appendingPathComponent on URL insteadxcode 显示错误 - 'appendingPathComponent' 不可用:在 URL 上使用 appendingPathComponent
【发布时间】:2021-05-04 03:52:26
【问题描述】:

我知道以前有人问过这个问题,但在我的情况下如何解决这个问题 -

 import Stripe

 class MyAPIClient: NSObject, STPCustomerEphemeralKeyProvider {
 let baseURL = "https://api.stripe.com"
 func createCustomerKey(withAPIVersion apiVersion: String, completion: @escaping STPJSONResponseCompletionBlock) {
 let url = self.baseURL.appendingPathComponent("ephemeral_keys")  /*1st error - 'appendingPathComponent' is unavailable: Use appendingPathComponent on URL instead.*/
 var urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: false)! /*2nd error - Cannot convert value of type 'String' to expected argument type 'URL'*/
 urlComponents.queryItems = [URLQueryItem(name: "api_version", value: apiVersion)]
 var request = URLRequest(url: urlComponents.url!)
 request.httpMethod = "POST"
 let task = URLSession.shared.dataTask(with: request, completionHandler: { (data, response, error) in
 guard let response = response as? HTTPURLResponse,
 response.statusCode == 200,
 let data = data,
 let json = ((try? JSONSerialization.jsonObject(with: data, options: []) as? [String : Any]) as [String : Any]??) else {
            completion(nil, error)
            return
        }
        completion(json, nil)
    })
    task.resume()
   }
 }

i) 我正在使用

a) 迅速

b)火库

c) nodejs - 我应该使用其他东西来代替 node js 吗?

另外,我还应该做哪些其他修改?欢迎所有其他建议。

【问题讨论】:

  • baseURL 是一个字符串。 appendingPathComponent(_:)(NS)URL 方法,而不是字符串方法。 init(url:resolvingAgainstBaseURL:) 的第一个参数需要 URL,而不是 String。停止混合类型,仔细阅读它们。它们可能看起来很相似,但就像橘子和柑桔。不同。
  • @Larme 令人困惑的是,API 仍然存在于NSString

标签: ios stripe-payments


【解决方案1】:

Apple 已将String 的路径修改API 长期移除。

您必须创建一个 URL,这就是错误的提示

let baseURL = URL(string: "https://api.stripe.com")!

【讨论】:

  • 菜鸟错误。谢谢,错误现在消失了。另外,我正在使用 node.js。这是最好的事情吗?还有什么建议吗?
  • 我对node.js不熟悉,抱歉。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-06-18
  • 2017-12-18
  • 2017-10-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-24
相关资源
最近更新 更多