SKStoreProductViewController

1、添加库

#import <StoreKit/StoreKit.h>

 2、添加代理

<SKStoreProductViewControllerDelegate>

 3、添加逻辑代码

- (void)evaluate

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

        
        __weak __typeof(self) weakself = self;
        
        SKStoreProductViewController *product = [[SKStoreProductViewController alloc] init];
        
        product.delegate = self;
        
        [product loadProductWithParameters:@{SKStoreProductParameterITunesItemIdentifier:@"xxxx"} completionBlock:^(BOOL result, NSError *error) {
            
            __strong __typeof(weakself) strongself = weakself;
            

            if (error) {
                
                NSLog(@"error = %@ with userinfo = %@",error,[error userInfo]);
                
            } else {
                
                [strongself presentViewController:product animated:YES completion:nil];
                
            }
            
        }];
        
    }
    
    else
        
    {
        //http://itunes.apple.com/us/app/id%d
        
        //http://itunes.apple.com/us/app/id
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://itunes.apple.com/us/app/idxxxxx"]];
        
    }
    
}

- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController

{
    
    [self dismissViewControllerAnimated:YES completion:nil];
    
}

 4、SKStoreProductViewController跳转截图

 

 

5、openURL截图

 

posted @ 2016-05-27 17:25  索马里猫  阅读(353)  评论(0编辑  收藏  举报