调用 Alamofire swift 时的额外参数 'method' 4
Extra argument 'method' in call Alamofire swift 4
我正在尝试从一个设备向另一个设备发送通知我之前在我的其他应用程序上已经这样做过但由于某种原因我收到了这条错误消息
Extra argument 'method' in call
在方法的 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)
}
}
我正在尝试从一个设备向另一个设备发送通知我之前在我的其他应用程序上已经这样做过但由于某种原因我收到了这条错误消息
Extra argument 'method' in call
在方法的 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)
}
}