BMLTSession
class BMLTSession : NSObject, URLSessionDataDelegate, BMLTCommunicatorDataSourceProtocol
This manages an interactive session connection with the server.
For whatever reason, Cocoa/Swift won’t let me derive from NSURLSession, so this class aggregates it, as opposed to extends it (not a big deal, probably better design in the long run anyway).
The semantic administration requires a constant session. Authentication is done once during the session, then the server maintains the authentication for the duration of the session. For this reason, we need to maintain a consistent session throughout our administration duties. This class is instantiated once by the App Delegate, and holds the session open.
This class maintains a dictionary of completion blocks that it uses to forward server responses to the users of this class. User instances need to define a completion block/callback, in the RequestCompletionBlock format. When they call a URL with this class, they provide this completion block. When the class instance gets the response, it forwards the data as an NSData instance to the completion block.
-
This class allows us to
See moretag
tasks with a completion block, allowing better autonomy.Declaration
Swift
class BMLTSessionTaskData
-
This is our session.
Declaration
Swift
var mySession: URLSession!
-
This will be set to true if the URL call is expected to fail (suppresses error report).
Declaration
Swift
var suppressErrors: Bool -
This is true if this is an SSL session
Declaration
Swift
var isSSL: Bool -
We are strictly linear. No concurrent I/O. We have just one job, and we do it through completion.
Declaration
Swift
var myCurrentTask: BMLTSession.BMLTSessionTaskData!
-
Make sure we clean up after ourselves.
Declaration
Swift
deinit -
Pretty much exactly what it says on the tin.
Declaration
Swift
func disconnectSession() -
Declares the connection status.
Declaration
Swift
func isSessionConnected() -> BoolReturn Value
a Bool, true if the session is currently connected.
-
Called when a session throws a nutty.
Declaration
Swift
func urlSession(_ inSession: URLSession, didBecomeInvalidWithError inError: Error?)Parameters
inSessionThe NSURLSession that controls this task.
errorThe error returned.
-
Called as the task receives data.
Declaration
Swift
func urlSession(_ inSession: URLSession, dataTask: URLSessionDataTask, didReceive: Data)Parameters
inSessionThe NSURLSession that controls this task.
dataTaskThe task that triggered this callback.
didReceivethe received data piece.
-
Called when a task has completed. We use this call to extract a JSON object from the response, then pass that object to the next handler.
Declaration
Swift
func urlSession(_ inSession: URLSession, task: URLSessionTask, didCompleteWithError error: Error?)Parameters
inSessionThe NSURLSession that controls this task.
taskThe task that triggered this callback.
errorAny error that occurred.
-
Calls a URL
Declaration
Swift
func callURI(_ inCommunicator: BMLTCommunicator, inURIAsAString: String!, inCompletionBlock: BMLTCommunicator.RequestCompletionBlock!) -> BoolParameters
inCommunicatorThe communicator instance calling this.
inURIAsAStringThis contains a string, with the URI.
inCompletionBlockThis is the completion block supplied by the caller. It is to be called upon receipt of data.
inIsTestIf true, then we don’t report task errors (the call is expected to fail).
Return Value
a Bool. True, if the call was successfully initiated.
-
This is a call that is made to validate an SSL security challenge (session variant).
Declaration
Swift
func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void)Parameters
sessionThe session thatt’s running the connection being challenged.
challengeThe challenge type
completionHandlerThe handler we need to call with our response.
-
This is a call that is made to validate an SSL security challenge (task variant).
Declaration
Swift
func urlSession(_ session: URLSession, task: URLSessionTask, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void)Parameters
sessionThe session thatt’s running the connection being challenged.
taskThe actual URL task that resulted in this challenge.
challengeThe challenge type
completionHandlerThe handler we need to call with our response.
View on GitHub
BMLTSession Class Reference