應(yīng)用內(nèi)打開app 在AppStore詳情頁(yè)
- 導(dǎo)入
#import <StoreKit/StoreKit.h>
- 實(shí)現(xiàn)代理
SKStoreProductViewControllerDelegate
創(chuàng)建并打開頁(yè)面
- (void)showAppStoreReviewId:(NSString *)appId
{
SKStoreProductViewController *storeProductVC = [[SKStoreProductViewController alloc]init];
storeProductVC.delegate = self;
NSDictionary *dict = [NSDictionary dictionaryWithObject:appId forKey:SKStoreProductParameterITunesItemIdentifier];
[storeProductVC loadProductWithParameters:dict completionBlock:^(BOOL result, NSError * _Nullable error) {
if (!error) {
[self presentViewController:storeProductVC animated:YES completion:nil];
}
}];
}
//點(diǎn)擊了完成按鈕
- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController
{
NSLog(@" 評(píng)價(jià)完成");
[self dismissViewControllerAnimated:YES completion:nil];
}
應(yīng)用內(nèi)評(píng)價(jià)
- (void)addAppReviewWithAppId:(NSString *)appId{
UIAlertController * alertVC = [UIAlertController alertControllerWithTitle:@"親喜歡**APP么?給個(gè)五星好評(píng)吧!" message:nil preferredStyle:UIAlertControllerStyleAlert];
//跳轉(zhuǎn)APPStore 中應(yīng)用的撰寫評(píng)價(jià)頁(yè)面
UIAlertAction *review = [UIAlertAction actionWithTitle:@"我要吐槽" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSURL *appReviewUrl = [NSURL URLWithString:[NSString stringWithFormat: @"itms-apps://itunes.apple.com/app/id%@?action=write-review",appId]];
CGFloat version = [[[UIDevice currentDevice]systemVersion]floatValue];
if (version >= 10.0) {
[[UIApplication sharedApplication] openURL:appReviewUrl options:@{} completionHandler:nil];
}else{
[[UIApplication sharedApplication] openURL:appReviewUrl];
}
}];
//不做任何操作
UIAlertAction *noReview = [UIAlertAction actionWithTitle:@"用用再說(shuō)" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[alertVC removeFromParentViewController];
}];
[alertVC addAction:review];
[alertVC addAction:noReview];
//判斷系統(tǒng),是否添加五星好評(píng)的入口
if (@available(iOS 10.3, *)) {
if([SKStoreReviewController respondsToSelector:@selector(requestReview)]){
UIAlertAction *fiveStar = [UIAlertAction actionWithTitle:@"五星好評(píng)" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[[UIApplication sharedApplication].keyWindow endEditing:YES];
// 五星好評(píng)
[SKStoreReviewController requestReview];
}];
[alertVC addAction:fiveStar];
}
} else {
// Fallback on earlier versions
}
dispatch_async(dispatch_get_main_queue(), ^{
[[[[UIApplication sharedApplication]keyWindow] rootViewController] presentViewController:alertVC animated:YES completion:nil];
});
}
應(yīng)用內(nèi)直接跳轉(zhuǎn)到AppStore應(yīng)用詳情頁(yè)、撰寫評(píng)論頁(yè)
- 應(yīng)用詳情頁(yè)
- (void)jumpToAppStroeDetialPageWithAppId:(NSString *)appId {
NSString *appUrl = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/cn/app/id%@?mt=8",appId];
if ([[UIApplication sharedApplication]canOpenURL:[NSURL URLWithString:appUrl]]) {
if (iOS_10_System_Later) {
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:appUrl] options:@{} completionHandler:nil];
} else {
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:appUrl]];
}
}
}
- 撰寫評(píng)論頁(yè)
- (void)jumpToAppStroeSortOrderPageWithAppId:(NSString *)appId {
NSString *appUrl = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/app/id%@?action=write-review",appId];
if ([[UIApplication sharedApplication]canOpenURL:[NSURL URLWithString:appUrl]]) {
if (iOS_10_System_Later) {
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:appUrl] options:@{} completionHandler:nil];
} else {
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:appUrl]];
}
}
}