ios - Alamofire 调用中的额外参数 'method'

标签 ios swift3 parameters alamofire

我搜索过这个问题,有很多答案,但没有一个能解决。我将参数定义为:

let parameters = [
                "name": username,
                "mobile": "",
                "email": email,
                "password": "",
                "blood_donor": "0",
                "registration_id": defaults.string(forKey: "FCMToken"),
                "platform": platform,
                "appID": "3"
            ]

之后当我发送请求时:

Alamofire.request(url, method: .post, parameters: parameters, encoding: URLEncoding(), headers: headers).responseJSON { response in

因此我收到有关参数的警告

Expression implicitly coerced from 'String?' to Any

如果我将 ! 放在参数旁边,我就会开始收到此错误:

Extra argument 'method' in call

我编写的所有函数是: func sendLoginCall(用户名:字符串,电子邮件:字符串,平台:字符串)。我尝试将 URLEncoding() 替换为 JSONEncoding.default 但没有成功。

我称之为这样的方法:

if let userName = data["name"], let email = data["email"] {
                            self.sendLoginCall(username: userName as! String, email: email as! String, platform: "fb")
                        }

最佳答案

parameters 类型更改为 [String : Any],如下所示:

let parameters = [
                "name": username,
                "mobile": "",
                "email": email,
                "password": "",
                "blood_donor": "0",
                "registration_id": defaults.string(forKey: "FCMToken"),
                "platform": platform,
                "appID": "3"
            ] as [String : Any]

不必要:从参数参数中删除 encoding: URLEncoding(),无需编码即可工作。

以下是 Alamofire 开发人员对同一问题和解决方案的讨论:https://github.com/Alamofire/Alamofire/issues?utf8=%E2%9C%93&q=extra%20argument

关于ios - Alamofire 调用中的额外参数 'method',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46524950/

相关文章:

objective-c - 使用图像和透明度自定义 UITabBar

ios - Swift 5 - 使用 Alamofire 上传 MultipartFormData 和图库中的图像

ios - 将 ios 的 "Player"框架更新为 swift 3

ios - 数组映射在Swift 3中不再起作用

iOS 10 : How to debug a Today Widget - "Unable to load" message

python - TensorFlow中的参数 "state_is_tuple"是干什么用的?

iphone - 核心数据和线程

python - Python 函数如何处理您传入的参数类型?

bash - 如何在扩展为匹配文件之前访问文字通配符参数?

ios - 返回值时 iOS 中的线程问题