I have built this struct:
struct Constants {
static let BASE_URL = "http://\(CameraManager.ip)/Nexus.cgi?"
static let WHOIAM_URL = "\(Constants.Url.BASE_URL)action=SERVERWhoAmI"
static var SERVERPING_URL = "\(Constants.Url.BASE_URL)session=\(CameraManager.session)&action=SERVERPing"
}
And the usage is as follows:
func refreshSession(success: @escaping () -> Void, failure: @escaping (String) -> Void) {
self.manager.request(Constants.Url.WHOIAM_URL, method:.get).authenticate(usingCredential: self.utiles.getDigestCredential()).responseJSON { (responseObject) -> Void in
if responseObject.result.isSuccess {
let value = responseObject.result.value
let json = JSON(value!)
print(CameraManager.session)
if self.parser.isError(json: json).0 {
failure(self.parser.isError(json: json).1)
} else {
self.failedPingCounter = 0
CameraManager.session = self.parser.parseWhoAmICall(json: json)
success()
}
}
}
func keepAlive(session: String, success: @escaping () -> Void, failure: @escaping (String) -> Void) {
self.manager.request(Constants.Url.SERVERPING_URL, method:.get).authenticate(usingCredential: self.utiles.getDigestCredential()).responseJSON { (responseObject) -> Void in
}
As you can see I am updating the CameraManager.session
value. After updating it I am using it in keepAlive
, yet when I check the request, I can see it uses the old one...
What is the best way to achieve what I want?