iOS 跳轉App Store 評論、評分
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 = @"983122949"; // 建立物件 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];