-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to set network timeout? #743
Comments
You can set it like as: import Foundation
import Alamofire
class DefaultAlamofireManager: Alamofire.SessionManager {
static let sharedManager: DefaultAlamofireManager = {
let configuration = URLSessionConfiguration.default
configuration.httpAdditionalHeaders = Alamofire.SessionManager.defaultHTTPHeaders
configuration.timeoutIntervalForRequest = 20 // as seconds, you can set your request timeout
configuration.timeoutIntervalForResource = 20 // as seconds, you can set your resource timeout
configuration.requestCachePolicy = .useProtocolCachePolicy
return DefaultAlamofireManager(configuration: configuration)
}()
} and you should put DefaultAlamofireManager into the your provider like this: let Provider = MoyaProvider<GithubAPI>(endpointClosure: endpointClosure,
manager: DefaultAlamofireManager.sharedManager,
plugins: [NetworkActivityPlugin(networkActivityClosure: networkActivityClosure)]) |
Does @haydarKarkin's answer solve your problem, @zeew? Let us know it doesn't :) |
Closing this for now @zeew, please re-open this if @haydarKarkin's solution doesn't solve your problem! |
@AndrewSB how To Target special setup? |
@mrdaios can you elaborate? |
public enum GitHub {
case zen
case userProfile(String)
case userRepositories(String)
case requestSomeThings
} Github.requestSomeThings may take a while, how to set timeout for this. @AndrewSB tks. |
You want to have a variable timeout based on the target? For example: you want |
yes。 |
Oh that would be interesting for me too since I'd like to avoid reference Alamofire directly |
Hmm, yeah. That's an interesting question. I don't know if we have a per-target timeout setup yet. The easiest thing right now, would be to add To get a better solution for per target timeouts, creating a new issue is probably the best idea, to get other people's opinions 😄 |
The default timeout >60s,I want to set it by myself.
thanks!
The text was updated successfully, but these errors were encountered: