LoginSignup
9
9

More than 5 years have passed since last update.

アプリ内にAppStoreをだいたい半分だけ表示してみる

Posted at

アプリ内にAppStoreを表示するために提供されているSKStoreProductViewControllerを使ってみた。

こちらのサイトを参考にさせていただきました。

参考:
SKStoreProductViewController
アプリ内でAppStoreを表示する方法

アプリ内AppStore

ViewController.h
#import <UIKit/UIKit.h>
#import <StoreKit/StoreKit.h>

@interface ViewController : UIViewController {
    // AppStore表示用のViewController
    SKStoreProductViewController *productViewController;
}
@end
ViewController.m
#import "ViewController.h"

@interface ViewController () <SKStoreProductViewControllerDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    productViewController = [[SKStoreProductViewController alloc] init];
    productViewController.delegate = self;

    self.modalPresentationStyle = UIModalPresentationFormSheet;

    [self presentViewController:productViewController animated:YES completion:^() {

        NSString *productID = @"646680221";
        NSDictionary *parameters = @{SKStoreProductParameterITunesItemIdentifier:productID};
        [productViewController loadProductWithParameters:parameters
                                         completionBlock:^(BOOL result, NSError *error)
         {}];
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController {
    [self dismissViewControllerAnimated:YES completion:nil];
}

@end

StoreKit.frameworkの追加を忘れないようにしましょう。

IMG_0320.jpg

半分だけ表示

半分だけ表示させたい気分だったので、だいたい半分くらい表示させてみた。

参考:
Modal Viewのサイズを変更しよう!

コードは以下の通りです。

ViewController.m

#import "ViewController.h"

@interface ViewController () <SKStoreProductViewControllerDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    productViewController = [[SKStoreProductViewController alloc] init];
    productViewController.delegate = self;

    self.modalPresentationStyle = UIModalPresentationFormSheet;
}

- (void)viewDidAppear:(BOOL)animated
{
    [self presentViewController:productViewController animated:YES completion:^() {

        NSString *productID = @"646680221";
        NSDictionary *parameters = @{SKStoreProductParameterITunesItemIdentifier:productID};
        [productViewController loadProductWithParameters:parameters
                                         completionBlock:^(BOOL result, NSError *error)
         {}];
    }];

    self.view.superview.frame = CGRectMake(0, 300, 320, 180);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController {
    [self dismissViewControllerAnimated:YES completion:nil];
}

IMG_0319.jpg

ちゃんと動きました。

入手ボタンを押してここからインストールできます。

9
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
9