Class NSURLConnection

  • All Implemented Interfaces:
    NSObject

    public class NSURLConnection
    extends NSObject
    NSURLConnection An NSURLConnection object provides support to perform asynchronous loads of a URL request, providing data to a client supplied delegate. The interface for NSURLConnection is very sparse, providing only the controls to start and cancel asynchronous loads of a URL request.

    An NSURLConnection may be used for loading of resource data directly to memory, in which case an NSURLConnectionDataDelegate should be supplied, or for downloading of resource data directly to a file, in which case an NSURLConnectionDownloadDelegate is used. The delegate is retained by the NSURLConnection until a terminal condition is encountered. These two delegates are logically subclasses of the base protocol, NSURLConnectionDelegate.

    A terminal condition produced by the loader will result in a connection:didFailWithError: in the case of an error, or connectiondidFinishLoading: or connectionDidFinishDownloading: delegate message.

    The -cancel message hints to the loader that a resource load should be abandoned but does not guarantee that more delegate messages will not be delivered. If -cancel does cause the load to be abandoned, the delegate will be released without further messages. In general, a caller should be prepared for -cancel to have no effect, and internally ignore any delegate callbacks until the delegate is released. Scheduling of an NSURLConnection specifies the context in which delegate callbacks will be made, but the actual IO may occur on a separate thread and should be considered an implementation detail.

    When created, an NSURLConnection performs a deep-copy of the NSURLRequest. This copy is available through the -originalRequest method. As the connection performs the load, this request may change as a result of protocol canonicalization or due to following redirects. -currentRequest can be used to retrieve this value.

    An NSURLConnections created with the +connectionWithRequest:delegate: or -initWithRequest:delegate: methods are scheduled on the current runloop immediately, and it is not necessary to send the -start message to begin the resource load.

    NSURLConnections created with -initWithRequest:delegate:startImmediately: are not automatically scheduled. Use -scheduleWithRunLoop:forMode: or -setDelegateQueue: to specify the context for delegate callbacks, and -start to begin the load. If you do not explicitly schedule the connection before -start, it will be scheduled on the current runloop and mode automatically.

    The NSURLConnectionSynchronousLoading category adds +sendSynchronousRequest:returningResponse:error, which blocks the current thread until the resource data is available or an error occurs. It should be noted that using this method on an applications main run loop may result in an unacceptably long delay in a user interface and its use is strongly discourage.

    The NSURLConnectionQueuedLoading category implements +sendAsynchronousRequest:queue:completionHandler, providing similar simplicity but provides a mechanism where the current runloop is not blocked.

    Both of the immediate loading categories do not provide for customization of resource load, and do not allow the caller to respond to, e.g., authentication challenges.

    • Constructor Detail

      • NSURLConnection

        protected NSURLConnection​(org.moe.natj.general.Pointer peer)
    • Method Detail

      • accessInstanceVariablesDirectly

        public static boolean accessInstanceVariablesDirectly()
      • allocWithZone

        public static java.lang.Object allocWithZone​(org.moe.natj.general.ptr.VoidPtr zone)
      • automaticallyNotifiesObserversForKey

        public static boolean automaticallyNotifiesObserversForKey​(java.lang.String key)
      • canHandleRequest

        public static boolean canHandleRequest​(NSURLRequest request)
        canHandleRequest: Performs a "preflight" operation that performs some speculative checks to see if a connection can be initialized, and the associated I/O that is started in the initializer methods can begin. The result of this method is valid only as long as no protocols are registered or unregistered, and as long as the request is not mutated (if the request is mutable). Hence, clients should be prepared to handle failures even if they have performed request preflighting by calling this method.
        Parameters:
        request - The request to preflight.
        Returns:
        YES if it is likely that the given request can be used to initialize a connection and the associated I/O can be started, NO otherwise.
      • cancelPreviousPerformRequestsWithTarget

        public static void cancelPreviousPerformRequestsWithTarget​(java.lang.Object aTarget)
      • cancelPreviousPerformRequestsWithTargetSelectorObject

        public static void cancelPreviousPerformRequestsWithTargetSelectorObject​(java.lang.Object aTarget,
                                                                                 org.moe.natj.objc.SEL aSelector,
                                                                                 java.lang.Object anArgument)
      • classFallbacksForKeyedArchiver

        public static NSArray<java.lang.String> classFallbacksForKeyedArchiver()
      • classForKeyedUnarchiver

        public static org.moe.natj.objc.Class classForKeyedUnarchiver()
      • connectionWithRequestDelegate

        @Deprecated
        public static NSURLConnection connectionWithRequestDelegate​(NSURLRequest request,
                                                                    java.lang.Object delegate)
        Deprecated.
      • debugDescription_static

        public static java.lang.String debugDescription_static()
      • description_static

        public static java.lang.String description_static()
      • hash_static

        public static long hash_static()
      • instanceMethodSignatureForSelector

        public static NSMethodSignature instanceMethodSignatureForSelector​(org.moe.natj.objc.SEL aSelector)
      • instancesRespondToSelector

        public static boolean instancesRespondToSelector​(org.moe.natj.objc.SEL aSelector)
      • isSubclassOfClass

        public static boolean isSubclassOfClass​(org.moe.natj.objc.Class aClass)
      • keyPathsForValuesAffectingValueForKey

        public static NSSet<java.lang.String> keyPathsForValuesAffectingValueForKey​(java.lang.String key)
      • new_objc

        public static java.lang.Object new_objc()
      • resolveClassMethod

        public static boolean resolveClassMethod​(org.moe.natj.objc.SEL sel)
      • resolveInstanceMethod

        public static boolean resolveInstanceMethod​(org.moe.natj.objc.SEL sel)
      • sendAsynchronousRequestQueueCompletionHandler

        @Deprecated
        public static void sendAsynchronousRequestQueueCompletionHandler​(NSURLRequest request,
                                                                         NSOperationQueue queue,
                                                                         NSURLConnection.Block_sendAsynchronousRequestQueueCompletionHandler handler)
        Deprecated.
        sendAsynchronousRequest:queue:completionHandler: Performs an asynchronous load of the given request. When the request has completed or failed, the block will be executed from the context of the specified NSOperationQueue. This is a convenience routine that allows for asynchronous loading of an url based resource. If the resource load is successful, the data parameter to the callback will contain the resource data and the error parameter will be nil. If the resource load fails, the data parameter will be nil and the error will contain information about the failure.
        Parameters:
        request - The request to load. Note that the request is deep-copied as part of the initialization process. Changes made to the request argument after this method returns do not affect the request that is used for the loading process.
        queue - An NSOperationQueue upon which the handler block will be dispatched.
        handler - A block which receives the results of the resource load.
      • sendSynchronousRequestReturningResponseError

        @Deprecated
        public static NSData sendSynchronousRequestReturningResponseError​(NSURLRequest request,
                                                                          org.moe.natj.general.ptr.Ptr<NSURLResponse> response,
                                                                          org.moe.natj.general.ptr.Ptr<NSError> error)
        Deprecated.
        sendSynchronousRequest:returningResponse:error: Performs a synchronous load of the given request, returning an NSURLResponse in the given out parameter. A synchronous load for the given request 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. For instance, the calling thread need not be running its run loop.
        Parameters:
        request - The request to load. Note that the request is deep-copied as part of the initialization process. Changes made to the request argument after this method returns do not affect the request that is used for the loading process.
        response - An out parameter which is filled in with the response generated by performing the load.
        error - Out parameter (may be NULL) used if an error occurs while processing the request. Will not be modified if the load succeeds.
        Returns:
        The content of the URL resulting from performing the load, or nil if the load failed.
      • setVersion_static

        public static void setVersion_static​(long aVersion)
      • superclass_static

        public static org.moe.natj.objc.Class superclass_static()
      • version_static

        public static long version_static()
      • cancel

        public void cancel()
      • initWithRequestDelegate

        @Deprecated
        public NSURLConnection initWithRequestDelegate​(NSURLRequest request,
                                                       java.lang.Object delegate)
        Deprecated.
      • initWithRequestDelegateStartImmediately

        @Deprecated
        public NSURLConnection initWithRequestDelegateStartImmediately​(NSURLRequest request,
                                                                       java.lang.Object delegate,
                                                                       boolean startImmediately)
        Deprecated.
        Designated initializer
      • newsstandAssetDownload

        public NKAssetDownload newsstandAssetDownload()
        [@property] newsstandAssetDownload A pointer to the asset download that this connection is associated with.
      • scheduleInRunLoopForMode

        public void scheduleInRunLoopForMode​(NSRunLoop aRunLoop,
                                             java.lang.String mode)
      • start

        public void start()
      • unscheduleFromRunLoopForMode

        public void unscheduleFromRunLoopForMode​(NSRunLoop aRunLoop,
                                                 java.lang.String mode)