• 在自己的apple中展示App Store中产品使用KStoreProductViewController


    KStoreProductViewController类是UIViewController的子类,。希望向用户展示App Store中产品时,需要:

    1.实例化一个SKStoreProductViewController类
    2.设置它的delegate
    3.把sotre product视图控制器显示给消费者

    剩下的就交给操作系统来处理了。需要记住一点的是SKStoreProductViewController只能以模态的方式显示。 SKStoreProductViewControllerDelegate协议定义了一个单独的方法— productViewControllerDidFinish:,当消费者离开App Store时会调用这个方法—一般是通过点击左上角画面中的取消按钮。通过给代理发送productViewControllerDidFinish:消 息,操作系统就会把控制权返回到你的程序。只支持IOS6.0及其以上

    步骤:

    1.添加 storeKit.framework

    2.头文件里 加上  

    #import <StoreKit/StoreKit.h>

    @interface ViewController : UIViewController<SKStoreProductViewControllerDelegate>

    3.直接在m中实现

    - (IBAction)action:(UIButton *)sender {
          [self goAppstore:@"xxxxxx"];//此处xxxxx需要替换为需要的appID
    }
    - (void)showAppInApp:(NSString *)_appId {
      Class isAllow = NSClassFromString(@"SKStoreProductViewController");
      if (isAllow != nil) {
        SKStoreProductViewController *storeVC = [[SKStoreProductViewController alloc] init];
        storeVC.delegate = self;
        [storeVC loadProductWithParameters:@{SKStoreProductParameterITunesItemIdentifier: _appId}
                          completionBlock:^(BOOL result, NSError *error) {
                            if (result) {
                              [self presentViewController:_SKSVC
                                                 animated:YES
                                               completion:nil];
                            }
                            else{
                              NSLog(@"%@",error);
                            }
                          }];
      }
      else{
        //低于iOS6没有这个类
        NSString *string = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/us/app/id%@?mt=8",_appId];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:string]];
      }
    }


    #pragma mark - SKStoreProductViewControllerDelegate 

    //对视图消失的处理
    - (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController {


      [viewController dismissViewControllerAnimated:YES
                                         completion:nil];


    }

     
  • 相关阅读:
    浅谈模块化开发
    用gulp搭建并发布自己的cli脚手架
    取值运算符新用法
    vue双向绑定之简易版
    获取对象属性之括号方式
    前端格式化工具之Prettier
    git操作之摘樱桃
    Sort
    MongoDB
    项目使用本地的包
  • 原文地址:https://www.cnblogs.com/canghaixiaoyuer/p/4707305.html
Copyright © 2020-2023  润新知