• 应用内打开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的效果进行微调设计就可以了。

  • 相关阅读:
    去除 SQL Server 查询结果中的两边空格
    Ubuntu 中安装 Oracle 10g
    不同格式的下拉列表框
    闲来无趣,写了个简单的JavaScript验证码
    Ubuntu 任务前后台调度管理
    C#数据类型转换,Convert
    OleDbType,C#,access 对应数据类型,互相对应
    SQL 将查询出的表当做 value 插入到表中
    asp.net mvc && asp.net 页面跳转
    asp.net mvc 与 asp.net结合(asp.net mvc 技巧)
  • 原文地址:https://www.cnblogs.com/cchHers/p/9099421.html
Copyright © 2020-2023  润新知