I have consuming OData from api url using swiftyJSON. Here api url is connected with VPN.
And api url looks like http://192.xxx.xx.xx:8000/sap/opu/odata/sap/Z_SRV/PRListSetSet?$format=json
When i run in simulator, i can able get data from odata api url but while running in device, no data received from odata api url. Since no vpn is connected to mobile device. how can i hard code my VPN programmactically to receive data in mobile?
here is how i'm getting data from OData api url:
typealias ServiceResponse = (JSON,Error?) -> Void
class PrListApiManager: NSObject {
static let sharedInstance = PrListApiManager()
let baseURL = apiUrlConstant.prListOdataUrl
func getPrList(onCompletion:@escaping (JSON) -> Void) {
let route = baseURL
makeHTTPGetRequest(path: route) { (json: JSON, error: Error?) in
onCompletion(json as JSON)
}
}
// MARK: perform a GET Request
private func makeHTTPGetRequest(path: String, onCompletion: @escaping ServiceResponse) {
let user = ApiloginConstant.user
let password = ApiloginConstant.password
let loginString = "\(user):\(password)"
guard let loginData = loginString.data(using: String.Encoding.utf8) else {
return
}
let base64LoginString = loginData.base64EncodedString()
print("base 64 login :\(base64LoginString)")
let headers = ["Authorization": "Basic \(base64LoginString)"]
// using URL and request getting a json
let request = URLRequest(url: NSURL(string: path)! as URL)
let config = URLSessionConfiguration.default
config.httpAdditionalHeaders = headers
let session = URLSession.init(configuration: config)
session.dataTask(with: request) { (data:Data?, response: URLResponse?, error:Error?) in
if let jsonData = data { // if data has a data and success
do {
let json: JSON = try JSON(data: jsonData)
onCompletion(json,nil)
print("json data:\(json)")
}catch {// error
onCompletion(JSON(),error)
}
} else { // if the data is nil
onCompletion(JSON(),error)
}
}.resume()
}