- (void)presentAppStoreForID:(NSNumber *)appStoreID inView:(UIView *)view withDelegate:(id<SKStoreProductViewControllerDelegate>)delegate withURL:(NSURL *)appStoreURL
{
if(NSClassFromString(@"SKStoreProductViewController")) { // iOS6 이상인지 체크
SKStoreProductViewController *storeController = [[SKStoreProductViewController alloc] init];
storeController.delegate = delegate; // productViewControllerDidFinish
NSDictionary *productParameters = @{ SKStoreProductParameterITunesItemIdentifier : appStoreID };
[storeController loadProductWithParameters:productParameters completionBlock:^(BOOL result, NSError *error) {
if (result) {
[self presentViewController:storeController animated:YES completion:nil];
} else {
[[[UIAlertView alloc] initWithTitle:@"연결 실패" message:@"앱을 불러올 수 없습니다." delegate:nil cancelButtonTitle:@"확인"otherButtonTitles: nil] show];
}
}];
} else { // iOS6 이하일 때
[[UIApplication sharedApplication] openURL:appStoreURL];
}
}
// 닫을 때
- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController {
[viewController dismissModalViewControllerAnimated:YES];
}