要想在App內(nèi)跳轉(zhuǎn)到特定App的詳情頁(yè)或者評(píng)論頁(yè),首先需要獲取到App的id。在iTunes Connect網(wǎng)站上登陸之后,選擇“我的App”,然后點(diǎn)擊某個(gè)特定的App進(jìn)入,在App信息的綜合信息中,會(huì)有一個(gè)“Apple ID”的條目,就是一串?dāng)?shù)字,這個(gè)就是對(duì)應(yīng)App的id了。
另外在App信息的額外信息中,點(diǎn)擊“在 App Store 中查看”會(huì)跳轉(zhuǎn)到一個(gè)特定鏈接的頁(yè)面,這個(gè)鏈接在下文中也會(huì)用到,這個(gè)鏈接會(huì)大概是這樣的"https://itunes.apple.com/us/app/fa-bu-ce-shi/idxxxxxxxxx?l=zh&ls=1&mt=8"。
一、iOS應(yīng)用內(nèi)跳轉(zhuǎn)到App Store詳情頁(yè)有兩種方式:
1、跳轉(zhuǎn)到App Store應(yīng)用中對(duì)應(yīng)App的詳情頁(yè)
(1)直接使用上文中獲取到的鏈接,通過(guò)openURL方法實(shí)現(xiàn),即
[[UIApplicationsharedApplication]openURL:[NSURLURLWithString:@"https://itunes.apple.com/us/app/fa-bu-ce-shi/idxxxxxxxxx?l=zh&ls=1&mt=8"]];
將上述鏈接中的https://更換為itms://或者itms-apps://也可以實(shí)現(xiàn)跳轉(zhuǎn)效果,但itms://開(kāi)頭的鏈接是跳轉(zhuǎn)到iTunes Store應(yīng)用中,https://與itms-apps://開(kāi)頭的鏈接是跳轉(zhuǎn)到App Store應(yīng)用中。
(2)利用上文獲取到的appId拼接成鏈接“itms-apps://itunes.apple.com/app/idxxxxxxxxx”,也通過(guò)openURL方法實(shí)現(xiàn),即
[[UIApplicationsharedApplication]openURL:[NSURLURLWithString:@"itms-apps://itunes.apple.com/app/idxxxxxxxxx"]];
2、在App內(nèi)部跳轉(zhuǎn)到指定App詳情頁(yè)
步驟為:
(1)導(dǎo)入相應(yīng)的框架
#import
(2)使當(dāng)前控制器遵守協(xié)議SKStoreProductViewControllerDelegate
(3)在應(yīng)當(dāng)跳轉(zhuǎn)方法中實(shí)現(xiàn)下列代碼,即創(chuàng)建SKStoreProductViewController控制器,設(shè)置代理,加載相應(yīng)內(nèi)容,在加載完成的回調(diào)中,等加載完成之后使用present的方式將視圖控制器呈現(xiàn)出來(lái)。
SKStoreProductViewController*storeProductVC = [[SKStoreProductViewControlleralloc]init];
storeProductVC.delegate=self;
[storeProductVCloadProductWithParameters:@{SKStoreProductParameterITunesItemIdentifier:@xxxxxxxxx}completionBlock:^(BOOLresult,NSError*_Nullableerror) {
if(error) {
NSLog(@"%@",[errorlocalizedDescription]);
}else{
NSLog(@"加載完成");
[selfpresentViewController:storeProductVCanimated:YEScompletion:^{
NSLog(@"界面彈出完成");
}];
}
}];
(4)實(shí)現(xiàn)SKStoreProductViewControllerDelegate的代理方法,即
- (void)productViewControllerDidFinish:(SKStoreProductViewController*)viewController{
NSLog(@"用戶(hù)請(qǐng)求頁(yè)面彈回");
[selfdismissViewControllerAnimated:YEScompletion:^{
NSLog(@"頁(yè)面彈回完成");
}];
}
當(dāng)用戶(hù)點(diǎn)擊取消時(shí),會(huì)執(zhí)行此代理方法,將控制器彈回即可。
二、iOS應(yīng)用內(nèi)跳轉(zhuǎn)到App Store評(píng)論頁(yè)有iOS7之前和之后的區(qū)別:跳轉(zhuǎn)方法一樣,但是鏈接不同,即
(1)iOS7之前
[[UIApplicationsharedApplication]openURL:[NSURLURLWithString:@"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=xxxxxxxxx"]];//iOS7之前跳轉(zhuǎn)到App評(píng)論頁(yè)
(2)iOS7之后
[[UIApplicationsharedApplication]openURL:[NSURLURLWithString:@"http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=xxxxxxxxx&pageNumber=0&sortOrdering=2&type=Purple+Software&mt=8"]];//iOS7之后跳轉(zhuǎn)到App評(píng)論頁(yè)