iOS 在应用内展示App Store 评分

2016-08-13  本文已影响174人  骑行怪状
女神
导入:#import <StoreKit/StoreKit.h>
签订代理:<SKStoreProductViewControllerDelegate>

- (void)viewDidLoad {
    [super viewDidLoad];


    UIButton *APPStoreStar = [UIButton buttonWithType:UIButtonTypeSystem];
    [self.view addSubview:APPStoreStar];
    APPStoreStar.backgroundColor = [UIColor colorWithRed:0.4272 green:0.4348 blue:0.0112 alpha:0.0];
    
    [APPStoreStar.titleLabel setFont:[UIFont systemFontOfSize:17]];
    [APPStoreStar setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
    [APPStoreStar setTitle:@"去 APP Store 评分" forState:UIControlStateNormal];
    [APPStoreStar setTintColor:[UIColor whiteColor]];
    [APPStoreStar addTarget:self action:@selector(starAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [APPStoreStar mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(ifeedBackInfoLineView.mas_bottom).offset(10);
        make.left.equalTo(weakSelf.view).offset(30);
        make.height.offset(30);
        make.width.offset(145);
        
        
    }];
    
}


###Tip : 注意:你可以在iTunes Connect找到app的唯一识别符,App Store中的每个app都有一个唯一识别符/Apple ID,注意你需要将在参数字典中以字符串的形式传递apple id。

- (void)starAction:(UIButton *)button{

    //初始化Product View Controller
    SKStoreProductViewController *storeProductViewController = [[SKStoreProductViewController alloc] init];
    //配置View Controller
    [storeProductViewController setDelegate:self];
    [storeProductViewController loadProductWithParameters:@{SKStoreProductParameterITunesItemIdentifier:@"这里填写应用 ID "}completionBlock:^(BOOL result, NSError *error){
       if(error)
       {
           NSLog(@"Error %@ with User Info %@.", error, [error userInfo]);
       }
       else
       {
           [self presentViewController:storeProductViewController animated:YES  completion:nil];
       }
   }];
    
    
    
}


-(void) productViewControllerDidFinish:(SKStoreProductViewController *)viewController
{
    [self dismissViewControllerAnimated:YES completion:nil];
}



上述代码没能实现,应用内撰写评价评分,可以使用如下的方法实现

NSString *str = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/app/idxxxxxx"];
 
 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
    
上一篇下一篇

猜你喜欢

热点阅读