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

  • 相关阅读:
    Mysql
    JavaScript常用事件
    css
    HTML
    判断pc还是手机打开跳转到别的网页
    queue 队列
    兼容firstChild和firstElementChild
    总结各种width,height,top,left
    原生js提取非行间样式
    ie8 不支持media
  • 原文地址:https://www.cnblogs.com/cchHers/p/9099421.html
Copyright © 2011-2022 走看看