一.通過SKStoreProductViewController (modal 樣式)實現(xiàn) 在當前應用內(nèi)打開 App Store
1.遵守 <SKStoreProductViewControllerDelegate>
2.實現(xiàn) <SKStoreProductViewControllerDelegate>
#pragma mark - Download HLM in SKStoreProductViewController
- (void)openAppFromAppStore:(NSString *)appid {
if (nil == appid || appid.length <= 0) {
return;
}
//loading
[SVProgressHUD show];
[SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeClear];
// // 改變導航欄的文字和圖片顏色
// [[UINavigationBar appearance] setTintColor:[UIColor greenColor]];
// // 紅色導航欄
// [[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];
// [UINavigationBar appearanceWhenContainedInInstancesOfClasses:@[[SKStoreProductViewController class]]];
//
SKStoreProductViewController *store = [[SKStoreProductViewController alloc] init];
store.delegate = self;
NSDictionary<NSString *, id> *parameters = @{SKStoreProductParameterITunesItemIdentifier: appid};
[store loadProductWithParameters:parameters completionBlock:^(BOOL result, NSError *error) {
// finish loading
[SVProgressHUD dismiss];
if (error) {
NSLog(@"error %@ with userInfo %@", error, [error userInfo]);
// 提示用戶發(fā)生了錯誤
// 或者通過 URL 打開 AppStore App.
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/in/app/id%@",HLMAPPID]];
[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:NULL];
} else {
[self presentViewController:store animated:YES completion:NULL];
}
}];
}
/// 用戶點擊取消會執(zhí)行該方法
- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController {
[viewController dismissViewControllerAnimated:YES completion:NULL];
}
3.SKStoreProductViewController只能通過 modal 方式打開,否則會報錯
二.通過openURL:options:completionHandler:方式,使用 scheme 為 itms-apps:// (push 樣式的) 啟動App Store應用 打開下載界面
//push 樣式的 App Store應用 打開下載界面 scheme > itms-apps://
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"itms-apps://itunes.apple.com/app/id%@",HLMAPPID]];
[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:NULL];
三.通過openURL:options:completionHandler:方式,使用 scheme 為 https://(push 樣式的) 啟動App Store應用 打開下載界面
//push 樣式的 App Store應用 打開下載界面 scheme > https://
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/in/app/id%@",HLMAPPID]];
[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:NULL];