iOS應(yīng)用評(píng)分的三種方式
ApplicationAppStoreIdentifier可以再iTunes上查找扯再。
1臼节、直接跳轉(zhuǎn)到AppStore,采用這種方式是要注意iOS版本要求的不同URL格式蝠筑,以iOS7.0為分水嶺(相信現(xiàn)在支持7.0之前版本的應(yīng)用應(yīng)該沒有了吧)番枚。
- (void)goToAppStore
{
NSString *urlStr = @"";
if ([[[UIDevice currentDevice] systemVersion] floatValue] > 7.0f)
{
urlStr = [NSString stringWithFormat:@"http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=%@&pageNumber=0&sortOrdering=2&type=Purple+Software&mt=8", ApplicationAppStoreIdentifier];
} else {
urlStr = [NSString stringWithFormat:@"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=%@", ApplicationAppStoreIdentifier];
}
NSURL *url = [NSURL URLWithString:urlStr];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
}
}
2咆瘟、內(nèi)置App Store評(píng)分瓤鼻,SKStoreProductViewController是蘋果提供的StoreKit.framework內(nèi)的控制器,添加StoreKit.framework,并導(dǎo)入 #import <StoreKit/StoreKit.h>手负,遵循SKStoreProductViewControllerDelegate方法涤垫。初始化后調(diào)用- (void)loadProductWithParameters:(NSDictionary<NSString *, id> *)parameters completionBlock:(nullable void(^)(BOOL result, NSError * __nullable error))block 方法,parameters中的參數(shù)是APPID竟终,該參數(shù)可以從ituns上獲取蝠猬。調(diào)用Block方法,模態(tài)彈出評(píng)分控制器: - (void)storeProductViewController
{
SKStoreProductViewController *storeProductViewContorller = [[SKStoreProductViewController alloc]init];
storeProductViewContorller.delegate=self;
[storeProductViewContorller loadProductWithParameters:@{SKStoreProductParameterITunesItemIdentifier:ApplicationAppStoreIdentifier}completionBlock:^(BOOL result,NSError *error) {
if(error) {
NSLog(@"error %@ with userInfo %@",error,[error userInfo]);
}else{
[self presentViewController:storeProductViewContorller animated:YES completion:nil];
}
}];
}
//代理方法必須實(shí)現(xiàn)统捶,監(jiān)聽storeProductViewContorller的取消按鈕
- (void)productViewControllerDidFinish:(SKStoreProductViewController*)viewController
{
[self dismissViewControllerAnimated:YES completion:nil];
}
3榆芦、評(píng)星級(jí),StoreKit.framework提供了SKStoreReviewController喘鸟,在調(diào)用+ (void)requestReview后會(huì)彈出評(píng)分框匆绣,可以選擇評(píng)分星級(jí),該方法只能應(yīng)用在iOS10.3之上什黑,不能寫評(píng)論: - (void)storeReviewController
{
if (@available(iOS 10.3, *)) {
[SKStoreReviewController requestReview];
} else {
NSLog(@"該方法只對(duì)iOS 10.3以上有效");
}
}