I have an asynchronous call to refresh my cookies in a new wkwebview
.
public override func viewDidLoad() {
super.viewDidLoad()
let cookies = cookieService.getCookies(forDomain: urlService.getTopLevelDomain())
authenticationService.authenticateIfNeeded { [weak self] error in
if let error = error {
print(failed)
} else {
self?.identityService.storeCookies(cookies) {
DispatchQueue.main.async {
self?.loadRequest()
}
}
}
}
public func authenticateIfNeeded(completion: @escaping (Error?) -> Void) {
let domain = urlService.getTopLevelDomain()
identityService.refreshCookies(for: domain, force: true, completion: completion)
}
I have put my network in a 100% packet loss preset.
The logic which has setcookies
in identity services has retry options and it takes 60 seconds in total to complete this retry calls.
func storeCookies(_ cookies: [AnyObject], completion: (() -> Void)? = nil) {
let group = DispatchGroup()
let httpCookies = cookies.compactMap { $0 as? HTTPCookie }
for httpCookie in httpCookies {
self.cookieStorageService.setCookie(httpCookie)
group.enter()
wkCookieStorage.setCookie(httpCookie) {
group.leave()
}
}
group.notify(queue: .main) {
completion?()
}
}
func refreshCookies(for domain: String, force: Bool, completion: @escaping VoidResultHandler) {
Retry<Void>.call(
shouldRetry: self.shouldRetryIdentityOperation,
handler: completion,
method: { completion in
self.identityOperations.refreshCookies(force: force, domain: domain, handler: { result in
switch result {
case .value(let cookies):
self.storeCookies(cookies) {
completion(.value(()))
}
case .error(let error):
completion(.error(error))
}
})
})
}
Till then I see a blank screen and then I get a retry option. How to reduce this delay to have a better user experience.