Skip to content

Commit

Permalink
Added a backgroundCompletionHandler and call it when the session fini…
Browse files Browse the repository at this point in the history
…shes background events.
  • Loading branch information
cnoon committed Jan 28, 2015
1 parent 330905e commit 582267b
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Source/Alamofire.swift
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,21 @@ public class Manager {
/// Whether to start requests immediately after being constructed. `true` by default.
public var startRequestsImmediately: Bool = true

/// The background completion handler closure provided by the UIApplicationDelegate `application:handleEventsForBackgroundURLSession:completionHandler:` method. By setting the background completion handler, the SessionDelegate `sessionDidFinishEventsForBackgroundURLSession` closure implementation will automatically call the handler. If you need to handle your own events before the handler is called, then you need to override the SessionDelegate `sessionDidFinishEventsForBackgroundURLSession` and manually call the handler when finished. `nil` by default.
public var backgroundCompletionHandler: (() -> Void)?

/**
:param: configuration The configuration used to construct the managed session.
*/
required public init(configuration: NSURLSessionConfiguration? = nil) {
self.delegate = SessionDelegate()
self.session = NSURLSession(configuration: configuration, delegate: delegate, delegateQueue: nil)

self.delegate.sessionDidFinishEventsForBackgroundURLSession = { [weak self] session in
if let strongSelf = self {
strongSelf.backgroundCompletionHandler?()
}
}
}

// MARK: -
Expand Down

0 comments on commit 582267b

Please sign in to comment.