StoreKit
SKStoreProductViewController
SDKs:iOS 6.0+
A SKStoreProductViewController object presents a store that allows the user to purchase other media from the App Store. For example, your app might display the store to allow the user to purchase another app.
Overview
To display a store, create a new SKStoreProductViewController object and set its delegate. Then, present the view controller modally from another view controller in your app. Your delegate dismisses the view controller when the user completes the purchase.
原文見官方文檔 SKStoreProductViewController
以下為演示代碼 及說明?
step 1: 需要導(dǎo)入#import <StoreKit/StoreKit.h>;
step 2: 需要遵守這個協(xié)議;
/**
? * 展示 app 信息
? *
? * appID: 應(yīng)用在蘋果商店的編號, 如圣斗士星矢:集結(jié):1090813843
? */
- (void)showStoreInfoView:(NSNumber *)appID {
? ? ? // Create a product dictionary using the selected product's iTunes identifer
? ? ? NSMutableDictionary* parametersDict = [[NSMutableDictionary alloc] init];
? ? ? [parametersDict setValue:appID forKey:SKStoreProductParameterITunesItemIdentifier];
? ? ? // Create a store product view controller
? ? ? SKStoreProductViewController* storeProductViewController = [[SKStoreProductViewController alloc] init];
? ? ? storeProductViewController.delegate = self;
? ? ? // Attempt to load the selected product from the App Store, display the store product view controller if success
? ? ? // and print an error message, otherwise.
? ? ? [storeProductViewController loadProductWithParameters:parametersDict
? ? ? completionBlock:^(BOOL result, NSError *error) {
? ? ? ? ? if(result) {
? ? ? ? ? ? ? ? [self presentViewController:storeProductViewController animated:YES completion:nil];
? ? ? ? ?} else {
? ? ? ? ? ? ? ?NSLog(@"Error message: %@",error.localizedDescription);
? ? ? ? ?}
? ? ? }];
}
#pragma mark Store product view controller delegate
// Used to dismiss the store view controller
- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController {
? ? ? [viewController.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}
其它:
SKStoreProductParameterITunesItemIdentifier是希望展示App的AppID踩身,該Key所關(guān)聯(lián)的值是一個NSNumber類型签杈。支持iOS6以后的系統(tǒng)版本。
SKStoreProductParameterAffiliateToken是附屬令牌乌奇,該Key所關(guān)聯(lián)的值是NSString類型。例如在iBook中app的ID,是iOS8中新添加的,支持iOS8以后的系統(tǒng)版本。
SKStoreProductParameterCampaignToken是混合令牌情组,該Key所關(guān)聯(lián)的值是一個40byte的NSString類型燥筷,使用這個令牌,你能看到點擊和銷售的數(shù)據(jù)報告院崇。支持iOS8以后的系統(tǒng)版本荆责。
本文參考:
1、蘋果官方文檔(SKStoreProductViewController)
2亚脆、蘋果官方demo
3、博客:StoreKit--SKStoreProductViewController
標(biāo)簽: iOS, iOS開發(fā), StoreKit, SKStoreProductViewController, APP 推廣