SKDownload Class Reference
| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/StoreKit.framework |
| Availability | Available in iOS 6.0 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
-
contentIdentifierproperty -
contentLengthproperty -
contentVersionproperty -
transactionproperty
Obtaining Information About the State of a Download
-
downloadStateproperty -
progressproperty -
timeRemainingproperty
Accessing a Completed Download
-
errorproperty -
contentURLproperty
Properties
contentIdentifier
A string that uniquely identifies the downloadable content. (read-only)
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 iOS 6.0 and later.
Declared In
SKDownload.hcontentLength
The length of the downloadable content, in bytes. (read-only)
Availability
- Available in iOS 6.0 and later.
Declared In
SKDownload.hcontentURL
The local location of the downloaded file. (read-only)
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 iOS 6.0 and later.
Declared In
SKDownload.hcontentVersion
A string that identifies which version of the content is available for download. (read-only)
Discussion
The version string must be formatted as a series of integers separated by periods.
Availability
- Available in iOS 6.0 and later.
Declared In
SKDownload.hdownloadState
The current state of the download object. (read-only)
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 downloadState property and use it to determine how to proceed. For more information on the different states, see “Download States.”
Availability
- Available in iOS 6.0 and later.
Declared In
SKDownload.herror
The error that prevented the content from being downloaded. (read-only)
Discussion
The value of this property is valid only when the downloadState property is set to SKDownloadStateFailed.
Availability
- Available in iOS 6.0 and later.
Declared In
SKDownload.hprogress
A value that indicates how much of the file has been downloaded. (read-only)
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 iOS 6.0 and later.
Declared In
SKDownload.htimeRemaining
An estimated time, in seconds, to finish downloading the content. (read-only)
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 iOS 6.0 and later.
Declared In
SKDownload.htransaction
The transaction associated with the downloadable file. (read-only)
Discussion
A download object is always associated with a payment transaction. The download object may only be queued after payment is processed and before the transaction is finished.
Availability
- Available in iOS 6.0 and later.
Declared In
SKDownload.hConstants
Download States
The states that a download operation can be in.
enum {
SKDownloadStateWaiting,
SKDownloadStateActive,
SKDownloadStatePaused,
SKDownloadStateFinished,
SKDownloadStateFailed,
SKDownloadStateCancelled,
};
typedef NSInteger SKDownloadState;
Constants
SKDownloadStateWaitingIndicates that the download has not started yet.
Available in iOS 6.0 and later.
Declared in
SKDownload.h.SKDownloadStateActiveIndicates that the content is currently being downloaded.
Available in iOS 6.0 and later.
Declared in
SKDownload.h.SKDownloadStatePausedIndicates that your app paused the download.
Available in iOS 6.0 and later.
Declared in
SKDownload.h.SKDownloadStateFinishedIndicates that the content was successfully downloaded.
Available in iOS 6.0 and later.
Declared in
SKDownload.h.SKDownloadStateFailedIndicates that an error occurred while the file was being downloaded.
Available in iOS 6.0 and later.
Declared in
SKDownload.h.SKDownloadStateCancelledIndicates that your app canceled the download.
Available in iOS 6.0 and later.
Declared in
SKDownload.h.
Download Time Values
Time values used to show special download states.
NSTimeInterval SKDownloadTimeRemainingUnknown;
Constants
© 2013 Apple Inc. All Rights Reserved. (Last updated: 2013-04-23)