美文网首页
(iOS)SKStoreProductViewControlle

(iOS)SKStoreProductViewControlle

作者: 爱恨的潮汐 | 来源:发表于2020-05-07 20:37 被阅读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
    

    相关文章

      网友评论

          本文标题:(iOS)SKStoreProductViewControlle

          本文链接:https://www.haomeiwen.com/subject/wiuzghtx.html