SKStoreProductViewController--便捷的APP宣传推广展示方式

本文详细介绍了SKStoreProductViewController的使用方法,包括如何创建并显示产品视图控制器、设置代理等,并提供了完整的示例代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

SKStoreProductViewController

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.

To choose a specific product, call the loadProductWithParameters:completionBlock: method, passing the iTunes item identifier for the item you want to sell.

 

Setting a Delegate

delegate

The store view controller’s delegate.

 

Loading a New Product Screen

- loadProductWithParameters:completionBlock:

Loads a new product screen to display.

 

Constants

Product Dictionary Keys

Keys supported in the product dictionary.

 

Guide

In-App Purchase Programming Guide

 

 

**************************************************************************************************************************

** 以下为演示代码 及说明 **

**************************************************************************************************************************

 

step 1: 需要导入#import <StoreKit/StoreKit.h>。

step 2: 需要遵守<SKStoreProductViewControllerDelegate>这个协议。

 

/**

* 展示 app 信息

*

* appID: 应用在苹果商店的编号, 如圣斗士星矢:集结: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所关联的值是一个NSNumber类型。支持iOS6以后的系统版本。
  • SKStoreProductParameterAffiliateToken是附属令牌,该Key所关联的值是NSString类型。例如在iBook中app的ID,是iOS8中新添加的,支持iOS8以后的系统版本。
  • SKStoreProductParameterCampaignToken是混合令牌,该Key所关联的值是一个40byte的NSString类型,使用这个令牌,你能看到点击和销售的数据报告。支持iOS8以后的系统版本。

本文参考:

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值