Skip to content

Instantly share code, notes, and snippets.

@choi-bong-sik
Created December 17, 2012 09:35
Show Gist options
  • Save choi-bong-sik/4317055 to your computer and use it in GitHub Desktop.
Save choi-bong-sik/4317055 to your computer and use it in GitHub Desktop.
SKStoreProduct test
-(void)linkAppsBtnCliekd
{
NSLog(@"%@ :: %@ ::",self,NSStringFromSelector(_cmd));
[self presentAppStoreForID:[NSNumber numberWithInt:407189619] inView:self.view withDelegate:self withURL:[NSURL URLWithString:@"https://itunes.apple.com/kr/app/neibeo-jisigin-yeogi-naver/id580057691?mt=8"]];
}
- (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];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment