I have old code from team where they were failing to parse Bool response.
NetworkManager.shared().firebaseTokenService(request: APIRouter.firebasetoken(param as [String : Any]), completion: { (httpResponse, jsonData, error) in
if httpResponse?.statusCode == 200 {
if let responseText = jsonData?.boolValue {
if (responseText) {
print("Success to send fcm token")
} else {
print("Failed to send fcm token")
}
} else {
print("Invalid response format")
}
} else {
print("Failed to send fcm token", error?.localizedDescription)
}
})
func firebaseTokenService(request: URLRequestConvertible, completion: @escaping (_ httpResponse: HTTPURLResponse?, _ responseObject:JSON?, _ error: Error?) -> Void) {
session.request(request, interceptor: nil).validate().responseJSON { (response) in
switch response.result {
case .success:
let json = JSON(response.data as Any)
completion(response.response, json, nil)
case .failure(let error):
completion(nil, nil, error)
}
}
}
The issue I am facing here is that the response is strictly coming as bool either true
or false
as attached image of postman.
I am getting success code 200, but jsonData
is always nil.
So please help me to parse the Bool response.
I can't change the code, as they have base class for all these, so only change I have to apply is in this method only.
Any help will be appreciated.