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

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: 需要导入#import <StoreKit/StoreKit.h>;

step 2: 需要遵守这个协议;

/**

  * 展示 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以后的系统版本。

本文参考:

1、苹果官方文档(SKStoreProductViewController)

2、苹果官方demo

3、博客:StoreKit--SKStoreProductViewController

标签: iOS, iOS开发, StoreKit, SKStoreProductViewController, APP 推广

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容