-
Notifications
You must be signed in to change notification settings - Fork 13
Home
The following instructions assume the use of Xcode 4. If you are using Xcode 3, the steps are similar, but different. ;)
- In Xcode 4, open the project you wish to add in app purchase functionality to
- In the finder, find the location of the "ASTStoreController.xcodeproj"
- Drag "ASTStoreController.xcodeproj" into a folder in your open Xcode project navigator view
- To simplify access to the public headers, select the "ASTStoreControllerHeaders" folder and drag a copy out of the ASTStoreController.xcodeproj enclosure and into somewhere else in your project
- In the "Project Navigator" select the target you wish to include the ASTStoreController in, and select the "Build Phases" tab. Under "Link Binary with Libraries", select the + sign and add libASTStoreController.a
The ASTStoreController is a singleton class. It is recommended that you initialize it in your AppDelegate so that it can process any outstanding transactions from the App Store as soon as possible.
- In your AppDelegate.m add the following in the header import section:
#import "ASTStoreController.h"
- In the AppDelegate.m function:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
Add the following code to initialize the ASTStoreController. This method assumes that lazy access to the app store is desired.
[ASTStoreController sharedStoreController];
- You should then initialize the controller with the list of products you wish to manage. For a simple application with a nonconsumable purchase you could use:
[[ASTStoreController sharedStoreController] setNonConsumableProductIdentifier:@"com.example.purchase"];
This function can be called multiple times to add multiple non-consumable product identifiers. For more complex in app purchase setup you are recommended to take advantage of the plist initialization format. For more details see TBD.
ASTStoreController allows for lazy initialization of the store. Why communicate with store if your customer doesn't enter your in-app store?
In your viewDidLoad or viewWillAppear methods, invoke the ASTStoreController method to start downloading the information from the app store.
[[ASTStoreController sharedStoreController].delegate = self;
[[ASTStoreController sharedStoreController] requestProductDataFromiTunes:NO];
It will then start issuing updates to the delegate via
- (void)astStoreControllerProductDataStateChanged:(ASTStoreControllerProductDataState)state;