iOS应用评分的三种方式
ApplicationAppStoreIdentifier可以再iTunes上查找。
1、直接跳转到AppStore,采用这种方式是要注意iOS版本要求的不同URL格式,以iOS7.0为分水岭(相信现在支持7.0之前版本的应用应该没有了吧)。
- (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、内置App Store评分,SKStoreProductViewController是苹果提供的StoreKit.framework内的控制器,添加StoreKit.framework,并导入 #import <StoreKit/StoreKit.h>,遵循SKStoreProductViewControllerDelegate方法。初始化后调用- (void)loadProductWithParameters:(NSDictionary<NSString *, id> *)parameters completionBlock:(nullable void(^)(BOOL result, NSError * __nullable error))block 方法,parameters中的参数是APPID,该参数可以从ituns上获取。调用Block方法,模态弹出评分控制器: - (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];
}
}];
}
//代理方法必须实现,监听storeProductViewContorller的取消按钮
- (void)productViewControllerDidFinish:(SKStoreProductViewController*)viewController
{
[self dismissViewControllerAnimated:YES completion:nil];
}
3、评星级,StoreKit.framework提供了SKStoreReviewController,在调用+ (void)requestReview后会弹出评分框,可以选择评分星级,该方法只能应用在iOS10.3之上,不能写评论: - (void)storeReviewController
{
if (@available(iOS 10.3, *)) {
[SKStoreReviewController requestReview];
} else {
NSLog(@"该方法只对iOS 10.3以上有效");
}
}