PSPDFDownloadManager

Objective-C

@interface PSPDFDownloadManager : NSObject

PSPDF_EMPTY_INIT_UNAVAILABLE

#pragma mark Configuration

/// The maximum number of concurrent downloads. Defaults to 2.
/// If `enableDynamicNumberOfConcurrentDownloads` is enabled, this property will change dynamically
/// and must be considered readonly.
@property (nonatomic) NSUInteger numberOfConcurrentDownloads;

/// Enable this property to let `PSPDFDownloadManager` decide what the best number of concurrent downloads
/// is depending on the network connection. Defaults to YES.
@property (nonatomic) BOOL enableDynamicNumberOfConcurrentDownloads;

/// The `PSPDFDownloadManager` delegate.
@property (nonatomic, weak) id<PSPDFDownloadManagerDelegate> delegate;

/// Controls if objects that are currently loading when the app moves to the background
/// should be completed in the background. Defaults to YES. iOS only.
@property (nonatomic) BOOL shouldFinishLoadingObjectsInBackground;

#pragma mark Enqueueing and Dequeueing Objects

/// See enqueueObject:atFront:. Enqueues the object at the end of the queue.
- (void)enqueueObject:(id<PSPDFRemoteContentObject>)object;

/// Enqueues an `PSPDFRemoteContentObject` for download. If the object is already downloading,
/// nothing is enqueued. If the object has been downloaded previously and has failed, it will be
/// removed from the failedObjects array and re-enqueued.
///
/// @param object The object to enqueue.
/// @param enqueueAtFront Set this to YES to add the object to the front of the queue.
- (void)enqueueObject:(id<PSPDFRemoteContentObject>)object atFront:(BOOL)enqueueAtFront;

/// Calls enqueueObject:atFont: multiple times. Enqueues the object at the end of the queue.
///
/// @param objects need to implement the `PSPDFRemoteContentObject` protocol.
- (void)enqueueObjects:(NSArray<id<PSPDFRemoteContentObject>> *)objects;

/// Calls enqueueObject:atFont: multiple times.
///
/// @param objects need to implement the `PSPDFRemoteContentObject` protocol.
- (void)enqueueObjects:(NSArray<id<PSPDFRemoteContentObject>> *)objects atFront:(BOOL)enqueueAtFront;

/// Cancels the download process for the given object.
///
/// @param object The object to be cancelled.
- (void)cancelObject:(id<PSPDFRemoteContentObject>)object;

/// Calls `cancelObject:` for all objects in `pendingObjects`, `loadingObjects`, and `failedObjects`.
- (void)cancelAllObjects;

#pragma mark State

/// The current reachability of the device.
@property (nonatomic, readonly) PSPDFReachability reachability;

/// Contains all objects waiting to be downloaded.
@property (nonatomic, copy, readonly) NSArray<id<PSPDFRemoteContentObject>> *waitingObjects;

/// Contains all currently loading objects.
@property (nonatomic, copy, readonly) NSArray<id<PSPDFRemoteContentObject>> *loadingObjects;

/// Contains all objects that have failed because of a network error and are scheduled for retry.
@property (nonatomic, copy, readonly) NSArray<id<PSPDFRemoteContentObject>> *failedObjects;

/// Helper that iterates loadingObjects, waitingObjects and failedObjects (in that order) and returns all matches.
- (NSArray<id<PSPDFRemoteContentObject>> *)objectsPassingTest:(BOOL (^)(id<PSPDFRemoteContentObject> obj, NSUInteger index, BOOL *stop))predicate;

/// Checks if the given object is currently handled by the download manager.
///
/// @param object The object.
/// @return YES if the download manager handles the object, that is if it is either pending, loading or failed.
- (BOOL)handlesObject:(id<PSPDFRemoteContentObject>)object;

/// Checks and returns the current state of a given object. If the object has never been enqueued,
/// `PSPDFDownloadManagerObjectStateNotHandled` will be returned.
///
/// @param object The object.
/// @return The state of the object.
- (PSPDFDownloadManagerObjectState)stateForObject:(id<PSPDFRemoteContentObject>)object;

@end

Swift

class DownloadManager : NSObject

Undocumented

  • Unavailable

    Not the designated initializer

    Undocumented

    Declaration

    Objective-C

    PSPDF_EMPTY_INIT_UNAVAILABLE
  • Unavailable

    Not the designated initializer

    Undocumented

    Declaration

    Objective-C

    PSPDF_EMPTY_INIT_UNAVAILABLE
  • The maximum number of concurrent downloads. Defaults to 2. If enableDynamicNumberOfConcurrentDownloads is enabled, this property will change dynamically and must be considered readonly.

    Declaration

    Objective-C

    @property (nonatomic) NSUInteger numberOfConcurrentDownloads;

    Swift

    var numberOfConcurrentDownloads: UInt { get set }
  • Enable this property to let PSPDFDownloadManager decide what the best number of concurrent downloads is depending on the network connection. Defaults to YES.

    Declaration

    Objective-C

    @property (nonatomic) BOOL enableDynamicNumberOfConcurrentDownloads;

    Swift

    var enableDynamicNumberOfConcurrentDownloads: Bool { get set }
  • The PSPDFDownloadManager delegate.

    Declaration

    Objective-C

    @property (nonatomic, weak) id<PSPDFDownloadManagerDelegate> _Nullable delegate;

    Swift

    weak var delegate: DownloadManagerDelegate? { get set }
  • Controls if objects that are currently loading when the app moves to the background should be completed in the background. Defaults to YES. iOS only.

    Declaration

    Objective-C

    @property (nonatomic) BOOL shouldFinishLoadingObjectsInBackground;

    Swift

    var shouldFinishLoadingObjectsInBackground: Bool { get set }
  • The current reachability of the device.

    Declaration

    Objective-C

    @property (nonatomic, readonly) PSPDFReachability reachability;

    Swift

    var reachability: ReachabilityStatus { get }
  • Contains all objects waiting to be downloaded.

    Declaration

    Objective-C

    @property (nonatomic, copy, readonly) NSArray<id<PSPDFRemoteContentObject>> *_Nonnull waitingObjects;
  • Contains all currently loading objects.

    Declaration

    Objective-C

    @property (nonatomic, copy, readonly) NSArray<id<PSPDFRemoteContentObject>> *_Nonnull loadingObjects;
  • Contains all objects that have failed because of a network error and are scheduled for retry.

    Declaration

    Objective-C

    @property (nonatomic, copy, readonly) NSArray<id<PSPDFRemoteContentObject>> *_Nonnull failedObjects;
  • Helper that iterates loadingObjects, waitingObjects and failedObjects (in that order) and returns all matches.

    Declaration

    Objective-C

    - (nonnull NSArray<id<PSPDFRemoteContentObject>> *)objectsPassingTest:
        (nonnull BOOL (^)(id<PSPDFRemoteContentObject> _Nonnull, NSUInteger,
                          BOOL *_Nonnull))predicate;
  • Checks if the given object is currently handled by the download manager.

    Declaration

    Objective-C

    - (BOOL)handlesObject:(nonnull id<PSPDFRemoteContentObject>)object;

    Parameters

    object

    The object.

    Return Value

    YES if the download manager handles the object, that is if it is either pending, loading or failed.

  • Checks and returns the current state of a given object. If the object has never been enqueued, PSPDFDownloadManagerObjectStateNotHandled will be returned.

    Declaration

    Objective-C

    - (PSPDFDownloadManagerObjectState)stateForObject:
        (nonnull id<PSPDFRemoteContentObject>)object;

    Parameters

    object

    The object.

    Return Value

    The state of the object.