1

I'm trying to use the firebase API in swift using Alamofire. I am having trouble adding headers and my request is saying there is an extra argument in my call.

public static func broadcastSyncDo(localId : String){
        let headers: HTTPHeaders = [
            "Authorization": "key=xxx",
            "Content-Type": "application/json"
        ]

        let parameters : [String : String] = [
            "to" : "/topics/"+localId,
            "content_available" : "1",
            "priority" : "high"
        ]


        Alamofire.request(.post, util_Constants.FIREBASE_API, headers : headers, parameters: parameters, encoding: URLEncoding.default)
            .responseJSON { response in
                print("response : \(response)")
        }
    }
user2363025
  • 6,365
  • 19
  • 48
  • 89

1 Answers1

1

There seems to be a small bug with Swift 3.0 and Alamofire 4.You have to make sure that all of your variables are of exactly the correct type otherwise you will get 'Extra parameter in call' error. Below is what your code should look like with all the correct types.

//requestString variable must be of type [String]
let requestString : String =  "https://yourURLHere"

//headers variable must be of type [String: String]
let headers: [String: String] = [
            "Authorization": "key=xxx",
            "Content-Type": "application/json"
        ]

//parameters variable must be of type [String : Any]
let parameters : [String : Any] = [
            "to" : "/topics/"+localId,
            "content_available" : "1",
            "priority" : "high"
        ]
 //Alamofire 4 uses a different .request syntax that Alamofire 3, so make sure you have the correct version and format.
 Alamofire.request(requestString, method: .post, parameters: parameters, encoding:
             URLEncoding.default, headers).responseString(completionHandler:  
    { responds in
    //some response from JSON code here.
})

This Link (Alamofire Swift 3.0 Extra parameter in call) will also help with further explain why you are getting this error.

Community
  • 1
  • 1
A. Welch
  • 356
  • 1
  • 3
  • 8