aaPanel_Jose
//MARK:- Post & Get Api Interaction
func postData(urlStr: String, params: Dictionary? = nil, showIndicator: Bool = true, completion: @escaping (ApiResponse?) -> Void) {
if NetworkReachabilityManager()!.isReachable {
if showIndicator {
Proxy.shared.showActivityIndicator()
}
AF.request("\(Apis.serverUrl)\(urlStr)",
method: .post,
parameters: params!,
encoding: URLEncoding.httpBody,
headers:[ "Authorization": "Bearer \(Proxy.shared.accessTokenNil())",
"User-Agent":"\(AppInfo.userAgent)"]).responseJSON { response in
debugPrint("Url,\(Apis.serverUrl)\(urlStr), Acces-Token, \(Proxy.shared.accessTokenNil())")
debugPrint("PostParam", "\(params!)")
Proxy.shared.hideActivityIndicator()
if response.data != nil && response.error == nil {
debugPrint("RESPONSE",response.value!)
debugPrint("JSON-RESPONSE", NSString(data: response.data!, encoding: String.Encoding.utf8.rawValue)!)
let dict = response.value as? [String:AnyObject]
if let dateCheck = dict!["datecheck"] as? String {
if !Proxy.shared.expiryDateCheckMethod(expiryDate: dateCheck) {
return
}
}
if response.response?.statusCode == 200 {
let res : ApiResponse?
res = ApiResponse(jsonData: response.data!, data: dict, message: dict!["message"] as? String ?? AlertTitle.success)
completion(res!)
} else if response.response?.statusCode == 400 {
Proxy.shared.displayStatusCodeAlert( dict!["error"] as? String ?? AlertTitle.error)
} else {
self.statusHandler(response.response, data: response.data, error: response.error as NSError?)
}
} else {
self.statusHandler(response.response, data: response.data, error: response.error as NSError?)
}
}
} else {
Proxy.shared.hideActivityIndicator()
Proxy.shared.openSettingApp()
}
}
func getData(urlStr: String, showIndicator: Bool = true, completion: @escaping (ApiResponse?) -> Void) {
if NetworkReachabilityManager()!.isReachable {
if showIndicator {
Proxy.shared.showActivityIndicator()
}
AF.request("\(Apis.serverUrl)\(urlStr)",
method: .get, parameters: nil,
encoding: JSONEncoding.default,
headers:[ "Authorization": "Bearer \(Proxy.shared.accessTokenNil())",
"User-Agent":"\(AppInfo.userAgent)"] ).responseJSON { response in
debugPrint("Url,\(Apis.serverUrl)\(urlStr), Acces-Token, \(Proxy.shared.accessTokenNil())")
Proxy.shared.hideActivityIndicator()
if response.data != nil && response.error == nil {
debugPrint("RESPONSE",response.value!)
debugPrint("JSON-RESPONSE", NSString(data: response.data!, encoding: String.Encoding.utf8.rawValue)!)
let dict = response.value as? [String:AnyObject]
if let dateCheck = dict!["datecheck"] as? String {
if !Proxy.shared.expiryDateCheckMethod(expiryDate: dateCheck) {
return
}
}
if response.response?.statusCode == 200 {
let res : ApiResponse?
res = ApiResponse(jsonData: response.data!, data: dict, message: dict!["message"] as? String ?? AlertTitle.success)
completion(res!)
} else if response.response?.statusCode == 400 {
Proxy.shared.displayStatusCodeAlert( dict!["error"] as? String ?? AlertTitle.error)
} else {
self.statusHandler(response.response, data: response.data, error: response.error as NSError?)
}
} else {
self.statusHandler(response.response, data: response.data, error: response.error as NSError?)
}
}
} else {
Proxy.shared.hideActivityIndicator()
Proxy.shared.openSettingApp()
}
}
\