要想在App內跳轉到特定App的詳情頁或者評論頁,首先需要獲取到App的id。在 iTunes Connect網站上登陸之后,選擇“我的App”,然后點擊某個特定的App進入,在App信息的綜合信息中,會有一個“Apple ID”的條目,就是一串數字,這個就是對應App的id了。另外在App信息的額外信息中, 點擊“在 App Store 中查看”會跳轉到一個特定鏈接的頁面,這個鏈接在下文中也會用到,這個鏈接會大概是這樣的"https://itunes.apple.com/us /app/fa-bu-ce-shi/idxxxxxxxxx?l=zh&ls=1&mt=8"。
一、iOS應用內跳轉到App Store詳情頁有兩種方式:
1、跳轉到App Store應用中對應App的詳情頁
(1)直接使用上文中獲取到的鏈接,通過openURL方法實現,即
[[UIApplicationsharedApplication] openURL:[NSURLURLWithString:@"https://itunes.apple.com/us/app/fa-bu-ce-shi/idxxxxxxxxx?l=zh&ls=1&mt=8"]];
將上述鏈接中的https://更換為itms://或者itms-apps://也可以實現跳轉效果,但itms://開頭的鏈接是跳轉到iTunes Store應用中,https://與itms-apps://開頭的鏈接是跳轉到App Store應用中。
(2)利用上文獲取到的appId拼接成鏈接“itms-apps://itunes.apple.com/app/idxxxxxxxxx”,也通過openURL方法實現,即
[[UIApplicationsharedApplication] openURL:[NSURLURLWithString:@"itms-apps://itunes.apple.com/app/idxxxxxxxxx"]];
2、在App內部跳轉到指定App詳情頁
步驟為:
(1)導入相應的框架
#import <StoreKit/StoreKit.h>
(2)使當前控制器遵守協議SKStoreProductViewControllerDelegate
(3)在應當跳轉方法中實現下列代碼,即創建
SKStoreProductViewController控制器,設置代理,加載相應內容,在加載完成的回調中,等加載完成之后使用present的方式將視圖控制器呈現出來。
SKStoreProductViewController *storeProductVC = [[SKStoreProductViewControlleralloc]init];
storeProductVC.
delegate = self;
[storeProductVC loadProductWithParameters:@{SKStoreProductParameterITunesItemIdentifier:@xxxxxxxxx}completionBlock:^(BOOL result, NSError * _Nullable error) {
if (error) {
NSLog(@"%@",[error localizedDescription]);
} else {
NSLog(@"加載完成");
[selfpresentViewController:storeProductVC animated:YEScompletion:^{
NSLog(@"界面彈出完成");
}];
}
}];
(4)實現SKStoreProductViewControllerDelegate的代理方法,即
- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController{
NSLog(@"用戶請求頁面彈回");
[selfdismissViewControllerAnimated:YEScompletion:^{
NSLog(@"頁面彈回完成");
}];
}
當用戶點擊取消時,會執行此代理方法,將控制器彈回即可。
二、iOS應用內跳轉到App Store評論頁有iOS7之前和之后的區別:跳轉方法一樣,但是鏈接不同,即
(1)iOS7之前
[[UIApplicationsharedApplication] openURL:[NSURLURLWithString:@"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=xxxxxxxxx"]];//iOS7之前跳轉到App評論頁
(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之后跳轉到App評論頁
轉自:http://blog.csdn.net/u012894479/article/details/50737365