SKDownload Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/StoreKit.framework
Availability
Available in OS X v10.8 and later.
Companion guide
Declared in
SKDownload.h

Overview

A SKDownload object represents downloadable content associated with a product. When you create a product in iTunes Connect, you can associate one or more pieces of downloadable content with it. Then, at runtime, when a product is purchased by a user, your app uses SKDownload objects to download the content from the App Store.

Your app never directly creates a SKDownload object. Instead, after a payment is processed, your app reads the transaction object’s downloads property to retrieve an array of SKDownload objects associated with the transaction. Then, to download the content, you queue a download object on the payment queue and wait for the content to be downloaded. After a download completes, read the download object’s contentURL property to get a URL to the downloaded content. Your app must process the downloaded file before completing the transaction. For example, it might copy the file into a directory whose contents are persistent. Once all downloads are complete, you finish the transaction. After the transaction is finished, the download objects cannot be queued to the payment queue and any URLs to the downloaded content are invalid.

Tasks

Obtaining Information About the Downloadable Content

Obtaining Information About the State of a Download

Accessing a Completed Download

Managing Downloaded Content

Properties

contentIdentifier

A string that uniquely identifies the downloadable content. (read-only)

@property(nonatomic, readonly) NSString *contentIdentifier
Discussion

Each piece of downloadable content associated with a product has its own unique identifier. The content identifier is specified in iTunes Connect when you add the content.

Availability
  • Available in OS X v10.8 and later.
Declared In
SKDownload.h

contentLength

The length of the downloadable content, in bytes. (read-only)

@property(nonatomic, readonly) long long contentLength
Availability
  • Available in OS X v10.8 and later.
Declared In
SKDownload.h

contentURL

The local location of the downloaded file. (read-only)

@property(nonatomic, readonly) NSURL *contentURL
Discussion

The value of this property is valid only when the downloadState property is set to SKDownloadStateFinished. The URL becomes invalid after the transaction object associated with the download is finalized.

Availability
  • Available in OS X v10.8 and later.
Declared In
SKDownload.h

contentVersion

A string that identifies which version of the content is available for download. (read-only)

@property(nonatomic, readonly) NSString *contentVersion
Discussion

The version string must be formatted as a series of integers separated by periods.

Availability
  • Available in OS X v10.8 and later.
Declared In
SKDownload.h

error

The error that prevented the content from being downloaded. (read-only)

@property(nonatomic, readonly) NSError *error
Discussion

The value of this property is valid only when the downloadState property is set to SKDownloadStateFailed.

Availability
  • Available in OS X v10.8 and later.
Declared In
SKDownload.h

progress

A value that indicates how much of the file has been downloaded. (read-only)

@property(nonatomic, readonly) float progress
Discussion

The value of this property is a floating point number between 0.0 and 1.0, inclusive, where 0.0 means no data has been download and 1.0 means all the data has been downloaded. Typically, your app uses the value of this property to update a user interface element, such as a progress bar, that displays how much of the file has been downloaded.

Do not use the value of this property to determine whether the download has completed. Instead, use the downloadState property.

Availability
  • Available in OS X v10.8 and later.
Declared In
SKDownload.h

state

The current state of the download object. (read-only)

@property(readonly) SKDownloadState state
Discussion

After you queue a download object, the payment queue object calls your transaction observer when the state of the download object changes. Your transaction observer should read the state property and use it to determine how to proceed. For more information on the different states, see “Download States.”

Availability
  • Available in OS X v10.8 and later.
Declared In
SKDownload.h

timeRemaining

An estimated time, in seconds, to finish downloading the content. (read-only)

@property(nonatomic, readonly) NSTimeInterval timeRemaining
Discussion

The system attempts to estimate how long it will take to finish downloading the file. If it cannot create a good estimate, the value of this property is set to SKDownloadTimeRemainingUnknown.

Availability
  • Available in OS X v10.8 and later.
Declared In
SKDownload.h

Class Methods

contentURLForProductID:

Returns the local location for the previously downloaded flie.

+ (NSURL *) contentURLForProductID:(NSString *)productID;
Parameters
productID

The product identifier.

Return Value

The local location for the previously downloaded flie.

Discussion

Use this method to locate the content on subsequent launches of your app.

Availability
  • Available in OS X v10.8 and later.
Declared In
SKDownload.h

deleteContentForProductID:

Deletes the previously downloaded file.

+ (void) deleteContentForProductID:(NSString *)productID;
Parameters
productID

The product identifier.

Availability
  • Available in OS X v10.8 and later.
Declared In
SKDownload.h

Constants

Download States

The states that a download operation can be in.

enum {
   SKDownloadStateWaiting,
   SKDownloadStateActive,
   SKDownloadStatePaused,
   SKDownloadStateFinished,
   SKDownloadStateFailed,
   SKDownloadStateCancelled,
};
typedef NSInteger SKDownloadState;
Constants
SKDownloadStateWaiting

Indicates that the download has not started yet.

Available in OS X v10.8 and later.

Declared in SKDownload.h.

SKDownloadStateActive

Indicates that the content is currently being downloaded.

Available in OS X v10.8 and later.

Declared in SKDownload.h.

SKDownloadStatePaused

Indicates that your app paused the download.

Available in OS X v10.8 and later.

Declared in SKDownload.h.

SKDownloadStateFinished

Indicates that the content was successfully downloaded.

Available in OS X v10.8 and later.

Declared in SKDownload.h.

SKDownloadStateFailed

Indicates that an error occurred while the file was being downloaded.

Available in OS X v10.8 and later.

Declared in SKDownload.h.

SKDownloadStateCancelled

Indicates that your app canceled the download.

Available in OS X v10.8 and later.

Declared in SKDownload.h.