(iOS)SKStoreProductViewControlle

2020-05-07  本文已影响0人  爱恨的潮汐

SKStoreProductViewController-模态出半截屏幕AppStore应用

SKStoreProductViewController-模态出半截屏幕AppStore应用
#import "HSVideoAdVC.h"
//内部打开app需要导入头文件
#import<StoreKit/StoreKit.h>
@interface HSVideoAdVC ()<SKStoreProductViewControllerDelegate>

@end

@implementation HSVideoAdVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self openAppStoreWithAppId:AppstoreId];
}
///App内部打开AppStore,传入对应App的AppId
- (void)openAppStoreWithAppId:(NSString*)appId {
    SKStoreProductViewController*storeProductVC =[[SKStoreProductViewController alloc] init];
    storeProductVC.delegate=self;
    NSDictionary*dict = [NSDictionary dictionaryWithObject:appId forKey:SKStoreProductParameterITunesItemIdentifier];
    [storeProductVC loadProductWithParameters:dict completionBlock:^(BOOL result,NSError*_Nullableerror) {
        if(result) {
            [self presentViewController:storeProductVC animated:YES completion:^{
                //处理模态出半截屏幕AppStore应用
                for(int i =0; i < storeProductVC.view.subviews.count; i++) {
                    UIView *subView = storeProductVC.view.subviews[i];
                    subView.frame = CGRectMake(0, 300, SCREEN_WIDTH, SCREEN_HEIGHT-300);
                }
            }];
        }
    }];
}
#pragma mark -点击关闭按钮
-(void)productViewControllerDidFinish:(SKStoreProductViewController*)viewController{
    NSLog(@"关闭界面");
    [viewController dismissViewControllerAnimated:YES completion:nil];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
上一篇下一篇

猜你喜欢

热点阅读