额外的参数'method'调用阿拉莫火雨燕 4



我正在尝试从设备发送到我之前在其他应用程序上执行此操作的设备,但由于某种原因我收到此错误消息

调用中的额外参数"方法">

在方法上的 alamofire.request 函数中。我已经在网上搜索了几个小时,我已经尝试了很多解决方案,但没有任何东西对我有用,无论我做什么,我都会收到相同的错误消息。

func setUpPushNotification(fromDevice: String) {

let title = ""
let body = "You got a friend request"
let toDeviceID = fromDevice
var headers:HTTPHeaders = HTTPHeaders()
let Method = Alamofire.HTTPMethod.post
headers = ["Content-Type":"application/json","Authorization":"key=(AppDelegate.SERVERKEY)"]
let notification = ["to":"(toDeviceID)","notification":["body":body,"title":title,"badge":1,"sound":"default"]] as [String : Any]

Alamofire.request(AppDelegate.NOTIFICATION_URL as URLConvertible,
method: Method,
parameters: notification,
encoding: JSONEncoding.default,
headers: headers).responseJSON { (response) in
print(response)
}

}

谢谢你的时间。 :)

AppDelegate中的AppDelegate.NOTIFICATION_URL变量有问题。

因为当我删除密钥时,这段代码开始工作。希望这能帮助您找到解决方案。

func setUpPushNotification(fromDevice: String) {
let title = ""
let url = "something"
let body = "You got a friend request"
let toDeviceID = fromDevice
var headers:HTTPHeaders = HTTPHeaders()
let Method = Alamofire.HTTPMethod.post
headers = ["Content-Type":"application/json","Authorization":"key=1236"]
let notification = ["to":"(toDeviceID)","notification":["body":body,"title":title,"badge":1,"sound":"default"]] as [String : Any]
Alamofire.request(url as URLConvertible , method: Method, parameters: notification, encoding: JSONEncoding.default, headers: headers)
}

appDelegate 是问题所在。 当我替换使用它的 2 val 时,它可以解决问题:

func setUpPushNotification(fromDevice: String) {

let title = ""
let body = "You got a friend request"
let toDeviceID = fromDevice
var headers:HTTPHeaders = HTTPHeaders()
let Method = Alamofire.HTTPMethod.post
headers = ["Content-Type":"application/json","Authorization":"key="]
let notification = ["to":"(toDeviceID)","notification":["body":body,"title":title,"badge":1,"sound":"default"]] as [String : Any]

Alamofire.request("www...",
method: Method,
parameters: notification,
encoding: JSONEncoding.default,
headers: headers).responseJSON { (response) in
print(response)
}
}

最新更新