1、跳转到App Store 直接编辑评论
NSString *APPID = @"xxxxxxxx";//app ID
NSString *nsStringToOpen = [NSString stringWithFormat: @"itms- apps://itunes.apple.com/app/id%@?action=write-review",APPID];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:nsStringToOpen]];
2、app内部直接评分
if (@available(iOS 10.3, *)) {
if([SKStoreReviewController respondsToSelector:@selector(requestReview)]) {
//防止键盘遮挡
[[UIApplication sharedApplication].keyWindow endEditing:YES];
[SKStoreReviewController requestReview];
}
}else {
// Fallback on earlier versions
}
3、跳转到某app下载页面 一般用与打广告
//第一种方式
NSString *appId = @"xxxxxxxx";
// 创建对象
SKStoreProductViewController *storeVC = [[SKStoreProductViewController alloc] init];
// 设置代理
storeVC.delegate = self;
// 初始化参数
NSDictionary *dict = [NSDictionary dictionaryWithObject:appId forKey:SKStoreProductParameterITunesItemIdentifier];
// 跳转App Store页
[storeVC loadProductWithParameters:dict completionBlock:^(BOOL result, NSError * _Nullable error) {
if (error) {
NSLog(@"错误信息:%@",error.userInfo);
}else{
// 弹出模态视图
[self presentViewController:storeVC animated:YES completion:nil];
}
}];
//第二种方式
Class allow = NSClassFromString(@"SKStoreProductViewController");
if (allow != nil && ![[UIDevice currentDevice].model isEqualToString:@"iPhone Simulator"]) {
NSLog(@"loading");
SKStoreProductViewController *product = [[SKStoreProductViewController alloc] init];
product.delegate = self;
[product loadProductWithParameters:@{SKStoreProductParameterITunesItemIdentifier:@"983122949"} completionBlock:^(BOOL result, NSError * _Nullable error) {
NSLog(@"completion");
NSLog(@"--%d-%@",result,error);
if (!error) {
[self presentViewController:product animated:YES completion:nil];
}else{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@""]];
}
}];
}
#pragma mark -- SKStoreProductViewControllerDelegate
/**
SKStoreProductViewControllerDelegate 方法,选择完成之后的处理
@param viewController SKStoreProductViewController
*/
- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController{
NSLog(@"将要退出 App Store 页面了");
[viewController dismissViewControllerAnimated:YES completion:^{
NSLog(@"已经退出 App Store 页面完成了");
}];
}
4、跳转评论
在iOS 11之前,为了让用户直接跳到App Store的评论页面,你的代码大概是这样写的:
-(void)goToAppStore{
NSString *itunesurl = @"[http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=XXXXXXXX&pageNumber=0&sortOrdering=2&type=Purple](https://links.jianshu.com/go?to=http%3A%2F%2Fitunes.apple.com%2FWebObjects%2FMZStore.woa%2Fwa%2FviewContentsUserReviews%3Fid%3DXXXXXXXX%26pageNumber%3D0%26sortOrdering%3D2%26type%3DPurple)+Software&mt=8";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:itunesurl]];
}
在iOS 11上不灵了,直接提示“无法连接App Store”!
我试了一下,果然如此,顺便看了一下其他家的APP,不少大厂的APP也掉进了这个坑里还没爬出来,比如饿了么,百度外卖等。经过搜索引擎的帮助,我找到了如下办法:
-(void)goToAppStore{
NSString *itunesurl = @"itms-[apps://itunes.apple.com/cn/app/idXXXXXX?mt=8&action=write-review](https://links.jianshu.com/go?to=apps%3A%2F%2Fitunes.apple.com%2Fcn%2Fapp%2FidXXXXXX%3Fmt%3D8%26action%3Dwrite-review)";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:itunesurl]];
}
注意:把里面的XXX替换成你自己的APP ID。 如果不知道 APP ID,打包到appstore 的时候有APP ID
iOS 11 跳转到app设置
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication]openURL:url];
网友评论