In-App Purchase Programming Guide - Apple Developer
In-App Purchase Programming Guide - Apple Developer
In-App Purchase Programming Guide - Apple Developer
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Delivering Products<br />
Waiting for the <strong>App</strong> Store to Process Transactions<br />
launched, Store Kit calls your transaction queue observer again and delivers the purchased content at that<br />
time. Similarly, if your app fails to mark a transaction as finished, Store Kit calls the observer every time your<br />
app is launched until the transaction is properly finished.<br />
Listing 4-1<br />
Registering the transaction queue observer<br />
- (BOOL)application:(UI<strong>App</strong>lication *)application<br />
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions<br />
{<br />
/* ... */<br />
}<br />
[[SKPaymentQueue defaultQueue] addTransactionObserver:observer];<br />
Implement the paymentQueue:updatedTransactions: method on your transaction queue observer. Store<br />
Kit calls this method when the status of a transaction changes—for example, when a payment request has<br />
been processed. The transaction status tells you what action your app needs to perform, as shown in Table<br />
4-1 and Listing 4-2.<br />
Table 4-1<br />
Status<br />
Transaction statuses and corresponding actions<br />
Action to take in your app<br />
SKPaymentTransactionStatePurchasing<br />
SKPaymentTransactionStateFailed<br />
SKPaymentTransactionState<strong>Purchase</strong>d<br />
SKPaymentTransactionStateRestored<br />
Update your UI to reflect the status, and wait to be<br />
called again.<br />
Use the value of the error property to present a<br />
message to the user.<br />
Provide the purchased functionality.<br />
Restore the previously purchased functionality.<br />
Listing 4-2<br />
Responding to transaction statuses<br />
- (void)paymentQueue:(SKPaymentQueue *)queue<br />
updatedTransactions:(NSArray *)transactions<br />
{<br />
for (SKPaymentTransaction *transaction in transactions) {<br />
switch (transaction.transactionState) {<br />
2013-10-22 | Copyright © 2013 <strong>App</strong>le <strong>In</strong>c. All Rights Reserved.<br />
24