应用内打开AppStore上某个应用的下载界面--SKStoreReviewController的使用

产品设计要求是这样的:

 

对应的初步代码是这样的: 

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    UIImageView *imageView = [[UIImageView alloc] init];
    imageView.frame = CGRectMake(0, 20, [UIScreen mainScreen].bounds.size.width, 200);
    imageView.image =  [UIImage imageNamed:@"123.jpeg"];
    [self.view addSubview:imageView];
    
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self showStoreProductInApp:@"423084029"];
}

- (void)showStoreProductInApp:(NSString *)appID{
    
    Class isAllow = NSClassFromString(@"SKStoreProductViewController");
    
    if (isAllow != nil) {
        
        SKStoreProductViewController *sKStoreProductViewController = [[SKStoreProductViewController alloc] init];
        [sKStoreProductViewController setDelegate:self];
        [sKStoreProductViewController.view setFrame:CGRectMake(0, 200, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height - 200)];
        
        [self.view addSubview:sKStoreProductViewController.view];
        
        __weak typeof(self) weakSelf = self;
        [sKStoreProductViewController loadProductWithParameters:@{SKStoreProductParameterITunesItemIdentifier: appID}
                                                completionBlock:^(BOOL result, NSError *error) {
                                                    __strong typeof(weakSelf) strongSelf = weakSelf;
                                                    
                                                    if (result) {
                                                        /*
                                                        // 也可以再这里实现该界面的预加载(会先出来一个连返回按钮都没有的空白页)
                                                        [strongSelf.view addSubview:sKStoreProductViewController.view];
                                                         */

                                                    }else{
                                                        NSLog(@"error:%@",error);
                                                    }
                                                }];
    }else{
        //低于iOS6的系统版本没有这个类,不支持这个功能
        NSString *string = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/xxxxxxx/app/id%@?mt=8",appID];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:string]];
    }
}

- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController {
    
    [viewController.view removeFromSuperview];
}

 

对应的初步效果是这样的:

 (<--- iOS11以后)(<--- iOS11之前)

后面再严格按照UE的效果进行微调设计就可以了。

转载于:https://www.cnblogs.com/cchHers/p/9099421.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值