0

I'm trying to send a notification from device to device i have done this before on my other app but for some reason i get this error message

Extra argument 'method' in call

inside the alamofire.request function on method. I have searched online for hours now and i have tryed a bunch of solutions but nothing has been working for me i get the same error message what ever i do.

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)
    }



}

thanks for your time. :)

Jiyar
  • 35
  • 10

2 Answers2

1

There is something wrong with your AppDelegate.NOTIFICATION_URL variable in the AppDelegate.

Because when I removed the key, the piece of code started working.. Hope this will help you find the solution.

    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)
}
Harsh
  • 2,852
  • 1
  • 13
  • 27
  • 1
    This worked i'am not sure why but i guess there was some code that hade The same name so i just change The var name on the URL. Thank You sir :) – Jiyar Oct 23 '18 at 07:44
0

The appDelegate is the problem. When i am replacing the 2 val that use it it fixes the issue :

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)
    }
}
ironRoei
  • 2,049
  • 24
  • 45