
女神
導(dǎo)入:#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,注意你需要將在參數(shù)字典中以字符串的形式傳遞apple id。
- (void)starAction:(UIButton *)button{
//初始化Product View Controller
SKStoreProductViewController *storeProductViewController = [[SKStoreProductViewController alloc] init];
//配置View Controller
[storeProductViewController setDelegate:self];
[storeProductViewController loadProductWithParameters:@{SKStoreProductParameterITunesItemIdentifier:@"這里填寫應(yīng)用 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];
}
上述代碼沒能實現(xiàn),應(yīng)用內(nèi)撰寫評價評分,可以使用如下的方法實現(xiàn)
NSString *str = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/app/idxxxxxx"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];