ios - 调用 Alamofire 时的额外参数 'method'
<p><p>我已经搜索过这个问题,有很多可用的答案,但没有一个能解决。我将参数定义为:</p>
<pre><code>let parameters = [
"name": username,
"mobile": "",
"email": email,
"password": "",
"blood_donor": "0",
"registration_id": defaults.string(forKey: "FCMToken"),
"platform": platform,
"appID": "3"
]
</code></pre>
<p>然后当我发送请求时:</p>
<pre><code>Alamofire.request(url, method: .post, parameters: parameters, encoding: URLEncoding(), headers: headers).responseJSON { response in
</code></pre>
<p>所以我收到关于 <code>parameters</code></p> 的警告
<blockquote>
<p>Expression implicitly coerced from 'String?' to Any</p>
</blockquote>
<p>如果我将 <code>!</code> 放在参数旁边,我开始收到此错误:</p>
<blockquote>
<p>Extra argument 'method' in call</p>
</blockquote>
<p>我写这一切的函数是:
<code>func sendLoginCall(username: String, email: String, platform: String)</code>.我尝试将 <code>URLEncoding()</code> 替换为 <code>JSONEncoding.default</code> 它没有用。</p>
<p>我称之为这样的方法:</p>
<pre><code>if let userName = data["name"], let email = data["email"] {
self.sendLoginCall(username: userName as! String, email: email as! String, platform: "fb")
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>将 <code>parameters</code> 类型更改为 <code></code> 如下:</p>
<pre><code>let parameters = [
"name": username,
"mobile": "",
"email": email,
"password": "",
"blood_donor": "0",
"registration_id": defaults.string(forKey: "FCMToken"),
"platform": platform,
"appID": "3"
] as
</code></pre>
<p>不需要:从参数参数中删除 <code>encoding: URLEncoding()</code>,它可以在没有编码的情况下工作。</p>
<p>以下是 Alamofire 开发人员对同一问题和解决方案的讨论:<a href="https://github.com/Alamofire/Alamofire/issues?utf8=%E2%9C%93&q=extra%20argument" rel="noreferrer noopener nofollow">https://github.com/Alamofire/Alamofire/issues?utf8=%E2%9C%93&q=extra%20argument</a> </p></p>
<p style="font-size: 20px;">关于ios - 调用 Alamofire 时的额外参数'method',我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/46524950/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/46524950/
</a>
</p>
页:
[1]