Class: NSURLConnection
Overview
An NSURLConnection object provides support to perform the loading of a URL request. The interface for NSURLConnection is sparse, providing only the controls to start and cancel asynchronous loads of a URL request.
Class Method Summary (collapse)
-
+ canHandleRequest:
Returns whether a request can be handled based on a preflight evaluation.
-
+ connectionWithRequest:delegate:
Creates and returns an initialized URL connection and begins to load the data for the URL request.
-
+ sendAsynchronousRequest:queue:completionHandler:
Loads the data for a URL request and executes a handler block on an operation queue when the request completes or fails.
-
+ sendSynchronousRequest:returningResponse:error:
Performs a synchronous load of the specified URL request.
Instance Method Summary (collapse)
-
- cancel
Cancels an asynchronous load of a request.
-
- currentRequest
Returns the current connection request.
-
- initWithRequest:delegate:
Returns an initialized URL connection and begins to load the data for the URL request.
-
- initWithRequest:delegate:startImmediately:
Returns an initialized URL connection and begins to load the data for the URL request, if specified.
-
- originalRequest
Returns a deep copy of the original connection request.
-
- scheduleInRunLoop:forMode:
Determines the run loop and mode that the connection uses to send messages to its delegate.
-
- setDelegateQueue:
Determines the operation queue that is used to send messages to the connection’s delegate.
-
- start
Causes the connection to begin loading data, if it has not already.
-
- unscheduleFromRunLoop:forMode:
Causes the connection to stop sending delegate messages using the specified run loop and mode.
Methods inherited from NSObject
#!, #!=, #!~, #, #==, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, alloc, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #eql?, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, #init, initialize, #initialize_clone, #initialize_copy, #initialize_dup, #inspect, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, #to_s, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version
Constructor Details
This class inherits a constructor from NSObject
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class NSObject
Class Method Details
+ (Boolean) canHandleRequest(request)
Returns whether a request can be handled based on a preflight evaluation. The result of this method is valid as long as no NSURLProtocol classes are registered or unregistered, and request remains unchanged. Applications should be prepared to handle failures even if they have performed request preflighting by calling this method.
+ (NSURLConnection) connectionWithRequest(request, delegate:delegate)
Creates and returns an initialized URL connection and begins to load the data for the URL request.
+ (Object) sendAsynchronousRequest(request, queue:queue, completionHandler:handler)
Loads the data for a URL request and executes a handler block on an operation queue when the request completes or fails. If the request completes successfully, the data parameter of the handler block contains the resource data, and the error parameter is nil. If the request fails, the data parameter is nil and the error parameter contain information about the failure.
+ (NSData) sendSynchronousRequest(request, returningResponse:response, error:error)
Performs a synchronous load of the specified URL request. A synchronous load is built on top of the asynchronous loading code made available by the class. The calling thread is blocked while the asynchronous loading system performs the URL load on a thread spawned specifically for this load request. No special threading or run loop configuration is necessary in the calling thread in order to perform a synchronous load.Important: Because this call can potentially take several minutes to fail (particularly when using a cellular network in iOS), you should never call this function from the main thread of a GUI application.If authentication is required in order to download the request, the required credentials must be specified as part of the URL. If authentication fails, or credentials are missing, the connection will attempt to continue without credentials.
Instance Method Details
- (Object) cancel
Cancels an asynchronous load of a request. After this method is called, the connection’s delegate no longer receives any messages for the connection. If you want to reattempt the connection, you should create a new connection object.
- (NSURLRequest) currentRequest
Returns the current connection request. As the connection performs the load, the request may change as a result of protocol canonicalization or due to following redirects. This method is be used to retrieve the current value.
- (Object) initWithRequest(request, delegate:delegate)
Returns an initialized URL connection and begins to load the data for the URL request. This is equivalent to calling initWithRequest:delegate:startImmediately: and passing YES for startImmediately.
- (Object) initWithRequest(request, delegate:delegate, startImmediately:startImmediately)
Returns an initialized URL connection and begins to load the data for the URL request, if specified.
- (NSURLRequest) originalRequest
Returns a deep copy of the original connection request. As the connection performs the load, this request may change as a result of protocol canonicalization or due to following redirects. The currentRequest method can be used to retrieve this value.
- (Object) scheduleInRunLoop(aRunLoop, forMode:mode)
Determines the run loop and mode that the connection uses to send messages to its delegate. By default, a connection is scheduled on the current thread in the default mode when it is created. If you create a connection with the initWithRequest:delegate:startImmediately: method and provide NO for the startImmediately parameter, you can schedule the connection on a different run loop or mode before starting it with the start method. You can schedule a connection on multiple run loops and modes, or on the same run loop in multiple modes.You cannot reschedule a connection after it has started.It is an error to schedule delegate messages with both this method and the setDelegateQueue: method.
- (Object) setDelegateQueue(queue)
Determines the operation queue that is used to send messages to the connection’s delegate. By default, a connection is scheduled on the current thread in the default mode when it is created. If you create a connection with the initWithRequest:delegate:startImmediately: method and provide NO for the startImmediately parameter, you can instead schedule the connection on an operation queue before starting it with the start method.You cannot reschedule a connection after it has started.It is an error to schedule delegate messages with both this method and the scheduleInRunLoop:forMode: method.
- (Object) start
Causes the connection to begin loading data, if it has not already. Calling this method is necessary only if you create a connection with the initWithRequest:delegate:startImmediately: method and provide NO for the startImmediately parameter. If you don’t schedule the connection in a run loop or an operation queue before calling this method, the connection is scheduled in the current run loop in the default mode.
- (Object) unscheduleFromRunLoop(aRunLoop, forMode:mode)
Causes the connection to stop sending delegate messages using the specified run loop and mode. By default, a connection is scheduled on the current thread in the default mode when it is created. If you create a connection with the initWithRequest:delegate:startImmediately: method and provide NO for the startImmediately parameter, you can instead schedule connection on a different run loop or mode before starting it with the start method. You can schedule a connection on multiple run loops and modes, or on the same run loop in multiple modes. Use this method to unschedule the connection from an undesired run loop and mode before starting the connection.You cannot reschedule a connection after it has started. It is not necessary to unschedule a connection after it has finished.