public class NSURLConnection extends NSObject
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.
| Modifier and Type | Class and Description |
|---|---|
static interface |
NSURLConnection.Block_sendAsynchronousRequestQueueCompletionHandler |
NSObject.Function_instanceMethodForSelector_ret, NSObject.Function_methodForSelector_ret| Modifier | Constructor and Description |
|---|---|
protected |
NSURLConnection(org.moe.natj.general.Pointer peer) |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
accessInstanceVariablesDirectly() |
static NSURLConnection |
alloc() |
static NSURLConnection |
allocWithZone(org.moe.natj.general.ptr.VoidPtr zone) |
static boolean |
automaticallyNotifiesObserversForKey(java.lang.String key) |
void |
cancel() |
static void |
cancelPreviousPerformRequestsWithTarget(java.lang.Object aTarget) |
static void |
cancelPreviousPerformRequestsWithTargetSelectorObject(java.lang.Object aTarget,
org.moe.natj.objc.SEL aSelector,
java.lang.Object anArgument) |
static boolean |
canHandleRequest(NSURLRequest request)
canHandleRequest:
|
static NSArray<java.lang.String> |
classFallbacksForKeyedArchiver() |
static org.moe.natj.objc.Class |
classForKeyedUnarchiver() |
static NSURLConnection |
connectionWithRequestDelegate(NSURLRequest request,
java.lang.Object delegate)
Deprecated.
|
NSURLRequest |
currentRequest() |
static java.lang.String |
debugDescription_static() |
static java.lang.String |
description_static() |
static long |
hash_static() |
NSURLConnection |
init() |
NSURLConnection |
initWithRequestDelegate(NSURLRequest request,
java.lang.Object delegate)
Deprecated.
|
NSURLConnection |
initWithRequestDelegateStartImmediately(NSURLRequest request,
java.lang.Object delegate,
boolean startImmediately)
Deprecated.
|
static NSObject.Function_instanceMethodForSelector_ret |
instanceMethodForSelector(org.moe.natj.objc.SEL aSelector) |
static NSMethodSignature |
instanceMethodSignatureForSelector(org.moe.natj.objc.SEL aSelector) |
static boolean |
instancesRespondToSelector(org.moe.natj.objc.SEL aSelector) |
static boolean |
isSubclassOfClass(org.moe.natj.objc.Class aClass) |
static NSSet<java.lang.String> |
keyPathsForValuesAffectingValueForKey(java.lang.String key) |
static NSURLConnection |
new_objc() |
NKAssetDownload |
newsstandAssetDownload()
[@property] newsstandAssetDownload
|
NSURLRequest |
originalRequest() |
static boolean |
resolveClassMethod(org.moe.natj.objc.SEL sel) |
static boolean |
resolveInstanceMethod(org.moe.natj.objc.SEL sel) |
void |
scheduleInRunLoopForMode(NSRunLoop aRunLoop,
java.lang.String mode) |
static void |
sendAsynchronousRequestQueueCompletionHandler(NSURLRequest request,
NSOperationQueue queue,
NSURLConnection.Block_sendAsynchronousRequestQueueCompletionHandler handler)
Deprecated.
|
static NSData |
sendSynchronousRequestReturningResponseError(NSURLRequest request,
org.moe.natj.general.ptr.Ptr<NSURLResponse> response,
org.moe.natj.general.ptr.Ptr<NSError> error)
Deprecated.
|
void |
setDelegateQueue(NSOperationQueue queue) |
static void |
setVersion_static(long aVersion) |
void |
start() |
static org.moe.natj.objc.Class |
superclass_static() |
void |
unscheduleFromRunLoopForMode(NSRunLoop aRunLoop,
java.lang.String mode) |
static long |
version_static() |
accessibilityActivate, accessibilityActivationPoint, accessibilityAssistiveTechnologyFocusedIdentifiers, accessibilityAttributedHint, accessibilityAttributedLabel, accessibilityAttributedUserInputLabels, accessibilityAttributedValue, accessibilityContainerType, accessibilityCustomActions, accessibilityCustomRotors, accessibilityDecrement, accessibilityDragSourceDescriptors, accessibilityDropPointDescriptors, accessibilityElementAtIndex, accessibilityElementCount, accessibilityElementDidBecomeFocused, accessibilityElementDidLoseFocus, accessibilityElementIsFocused, accessibilityElements, accessibilityElementsHidden, accessibilityFrame, accessibilityHint, accessibilityIncrement, accessibilityLabel, accessibilityLanguage, accessibilityNavigationStyle, accessibilityPath, accessibilityPerformEscape, accessibilityPerformMagicTap, accessibilityRespondsToUserInteraction, accessibilityScroll, accessibilityTextualContext, accessibilityTraits, accessibilityUserInputLabels, accessibilityValue, accessibilityViewIsModal, addObserverForKeyPathOptionsContext, attemptRecoveryFromErrorOptionIndex, attemptRecoveryFromErrorOptionIndexDelegateDidRecoverSelectorContextInfo, autoContentAccessingProxy, awakeAfterUsingCoder, awakeFromNib, class_objc, classForCoder, classForKeyedArchiver, copy, dealloc, debugDescription, description, dictionaryWithValuesForKeys, didChangeValueForKey, didChangeValueForKeyWithSetMutationUsingObjects, didChangeValuesAtIndexesForKey, doesNotRecognizeSelector, fileManagerShouldProceedAfterError, fileManagerWillProcessPath, finalize_objc, forwardingTargetForSelector, forwardInvocation, hash, indexOfAccessibilityElement, isAccessibilityElement, isEqual, isKindOfClass, isMemberOfClass, isProxy, methodForSelector, methodSignatureForSelector, mutableArrayValueForKey, mutableArrayValueForKeyPath, mutableCopy, mutableOrderedSetValueForKey, mutableOrderedSetValueForKeyPath, mutableSetValueForKey, mutableSetValueForKeyPath, observationInfo, observeValueForKeyPathOfObjectChangeContext, performSelector, performSelectorInBackgroundWithObject, performSelectorOnMainThreadWithObjectWaitUntilDone, performSelectorOnMainThreadWithObjectWaitUntilDoneModes, performSelectorOnThreadWithObjectWaitUntilDone, performSelectorOnThreadWithObjectWaitUntilDoneModes, performSelectorWithObject, performSelectorWithObjectAfterDelay, performSelectorWithObjectAfterDelayInModes, performSelectorWithObjectWithObject, prepareForInterfaceBuilder, provideImageDataBytesPerRowOrigin_Size_UserInfo, removeObserverForKeyPath, removeObserverForKeyPathContext, replacementObjectForCoder, replacementObjectForKeyedArchiver, respondsToSelector, self, setAccessibilityActivationPoint, setAccessibilityAttributedHint, setAccessibilityAttributedLabel, setAccessibilityAttributedUserInputLabels, setAccessibilityAttributedValue, setAccessibilityContainerType, setAccessibilityCustomActions, setAccessibilityCustomRotors, setAccessibilityDragSourceDescriptors, setAccessibilityDropPointDescriptors, setAccessibilityElements, setAccessibilityElementsHidden, setAccessibilityFrame, setAccessibilityHint, setAccessibilityLabel, setAccessibilityLanguage, setAccessibilityNavigationStyle, setAccessibilityPath, setAccessibilityRespondsToUserInteraction, setAccessibilityTextualContext, setAccessibilityTraits, setAccessibilityUserInputLabels, setAccessibilityValue, setAccessibilityViewIsModal, setIsAccessibilityElement, setNilValueForKey, setObservationInfo, setShouldGroupAccessibilityChildren, setValueForKey, setValueForKeyPath, setValueForUndefinedKey, setValuesForKeysWithDictionary, shouldGroupAccessibilityChildren, superclass, validateValueForKeyError, validateValueForKeyPathError, valueForKey, valueForKeyPath, valueForUndefinedKey, willChangeValueForKey, willChangeValueForKeyWithSetMutationUsingObjects, willChangeValuesAtIndexesForKeypublic static boolean accessInstanceVariablesDirectly()
public static NSURLConnection alloc()
public static NSURLConnection allocWithZone(org.moe.natj.general.ptr.VoidPtr zone)
public static boolean automaticallyNotifiesObserversForKey(java.lang.String key)
public static boolean canHandleRequest(NSURLRequest request)
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.
request - The request to preflight.public static void cancelPreviousPerformRequestsWithTarget(java.lang.Object aTarget)
public static void cancelPreviousPerformRequestsWithTargetSelectorObject(java.lang.Object aTarget,
org.moe.natj.objc.SEL aSelector,
java.lang.Object anArgument)
public static NSArray<java.lang.String> classFallbacksForKeyedArchiver()
public static org.moe.natj.objc.Class classForKeyedUnarchiver()
@Deprecated public static NSURLConnection connectionWithRequestDelegate(NSURLRequest request, java.lang.Object delegate)
public static java.lang.String debugDescription_static()
public static java.lang.String description_static()
public static long hash_static()
public static NSObject.Function_instanceMethodForSelector_ret instanceMethodForSelector(org.moe.natj.objc.SEL aSelector)
public static NSMethodSignature instanceMethodSignatureForSelector(org.moe.natj.objc.SEL aSelector)
public static boolean instancesRespondToSelector(org.moe.natj.objc.SEL aSelector)
public static boolean isSubclassOfClass(org.moe.natj.objc.Class aClass)
public static NSSet<java.lang.String> keyPathsForValuesAffectingValueForKey(java.lang.String key)
public static NSURLConnection new_objc()
public static boolean resolveClassMethod(org.moe.natj.objc.SEL sel)
public static boolean resolveInstanceMethod(org.moe.natj.objc.SEL sel)
@Deprecated public static void sendAsynchronousRequestQueueCompletionHandler(NSURLRequest request, NSOperationQueue queue, NSURLConnection.Block_sendAsynchronousRequestQueueCompletionHandler handler)
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 a 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.
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.@Deprecated public static NSData sendSynchronousRequestReturningResponseError(NSURLRequest request, org.moe.natj.general.ptr.Ptr<NSURLResponse> response, org.moe.natj.general.ptr.Ptr<NSError> 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.
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.public static void setVersion_static(long aVersion)
public static org.moe.natj.objc.Class superclass_static()
public static long version_static()
public void cancel()
public NSURLRequest currentRequest()
public NSURLConnection init()
@Deprecated public NSURLConnection initWithRequestDelegate(NSURLRequest request, java.lang.Object delegate)
@Deprecated public NSURLConnection initWithRequestDelegateStartImmediately(NSURLRequest request, java.lang.Object delegate, boolean startImmediately)
public NKAssetDownload newsstandAssetDownload()
A pointer to the asset download that this connection is associated with.
public NSURLRequest originalRequest()
public void scheduleInRunLoopForMode(NSRunLoop aRunLoop, java.lang.String mode)
public void setDelegateQueue(NSOperationQueue queue)
public void start()
public void unscheduleFromRunLoopForMode(NSRunLoop aRunLoop, java.lang.String mode)