美文网首页iOS 基础知识·底层原理
iOS 利用SKStoreProductViewControll

iOS 利用SKStoreProductViewControll

作者: 仲子 | 来源:发表于2015-11-10 17:37 被阅读3265次

iOS6以后,苹果提供了在应用内部打开App Store中某一个应用下载页面的方式,提供了 SKStoreProductViewController类进行支持

1、添加 #import

2、添加代理 SKStoreProductViewControllerDelegate

3、添加代码

- (void)evaluate

{

        Class isAllow = NSClassFromString(@"SKStoreProductViewController");

        if (isAllow != nil && ![[UIDevice currentDevice].model  isEqualToString:@"iPhone Simulator"])

        {

                [self showLoadingView];

                __weak __typeof(self) weakself = self;

                SKStoreProductViewController *product = [[SKStoreProductViewController alloc] init];

                 product.delegate = self;

                [product loadProductWithParameters:@{SKStoreProductParameterITunesItemIdentifier:@"APP ID"} completionBlock:^(BOOL result, NSError *error) {

                __strong __typeof(weakself) strongself = weakself;

                [strongself hideLoadingView];

                if (error) {

                        NSLog(@"error = %@ with userinfo = %@",error,[error userInfo]);

                } else {

                        [strongself presentViewController:product animated:YES completion:nil];

                }

                }];

        }

        else

        {

                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@""]];

        }

}

- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController

{

        [self dismissViewControllerAnimated:YES completion:nil];

}

相关文章

网友评论

    本文标题:iOS 利用SKStoreProductViewControll

    本文链接:https://www.haomeiwen.com/subject/zmdhhttx.html