Wednesday, November 11, 2026
HomeiOS DevelopmentURLSessionConfiguration.timeoutIntervalForResource not working?

URLSessionConfiguration.timeoutIntervalForResource not working?

[ad_1]

Does anybody know methods to delay obtain of web site, till web site operations are loaded.
My session object seems to be like this inside my ViewModel

personal lazy var session: URLSession = {
        let configuration = URLSessionConfiguration.ephemeral
        configuration.timeoutIntervalForResource = 300
        configuration.timeoutIntervalForRequest  = 30
        configuration.networkServiceType         = .responsiveData
        return URLSession(
            configuration: configuration,
            delegate: SessionDelegate(),
            delegateQueue: OperationQueue.important
        )
    }()
last class SessionDelegate: NSObject, URLSessionTaskDelegate {
    
}

I’ve a session delegate solely as a result of I believe that could possibly be the place you delay, nevertheless I’m not positive?
I’ve learn on apple docs for URLSessionConfiguration that timeoutIntervalForResource is the way you inform the session to attend for extra knowledge to be loaded, nevertheless once I obtain knowledge utilizing the next code:

let (knowledge, response) = strive await session.knowledge(from: url)
guard (response as? HTTPURLResponse)?.statusCode == 200
else { throw AppError.invaildServerResponse(url: url) }
let html = strive knowledge.encode(utilizing: .utf8)
let doc = strive SwiftSoup.parse(html)
guard let ingredient = strive doc.getElementsByClass("Q4iAWc").first() else {
   throw AppError.couldNotFetchElement
}
let string = strive ingredient.textual content()
return string

It doesn’t work.

In my prime degree job, in my do-catch-block, I catch AppError.couldNotFetchElement
That is because of the div not being loaded as a result of knowledge has not been fetch or computed on the web site. Does anybody know methods to delay obtain till knowledge is loaded whereas utilizing Swift Concurrency and never GCD.

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments