1、建立工程,匯入庫檔案:StoreKit.framework,並且匯入標頭檔,如下:
#import <StoreKit/StoreKit.h>
2、在需要點擊事件中,添加代碼,如下:
- (IBAction)gotoStore:(id)sender { // Initialize Product View Controller SKStoreProductViewController *storeProductViewController = [[SKStoreProductViewController alloc] init]; // Configure View Controller [storeProductViewController setDelegate:self]; [storeProductViewController loadProductWithParameters:@{SKStoreProductParameterITunesItemIdentifier : @"594467299"} completionBlock:^(BOOL result, NSError *error) { if (error) { NSLog(@"Error %@ with User Info %@.", error, [error userInfo]); } else { // Present Store Product View Controller [self presentViewController:storeProductViewController animated:YES completion:nil]; } }];}
3、設定協議 SKStoreProductViewControllerDelegate,並且實習協議中的方法,如下:
- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_6_0){ [self dismissViewControllerAnimated:YES completion:nil]; }
4、在真機上測試,即可實現效果。