我的版本是在這裏。
1)#import <StoreKit/StoreKit.h>
並設置SKStoreProductViewControllerDelegate
2)添加委託應答的方法,
- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController
{
// if user do cancel, close it
[viewController dismissViewControllerAnimated:YES completion:nil];
}
3)添加存儲開放代碼。
void SomeClassName::openAppStore(string appStoreId, string appUrl)
{
// below iOS 6.0
NSString *appUrlStatic = [NSString stringWithUTF8String:appUrl.c_str()];
// iOS 6.0 or above, appstore id is 9-digin number
NSString *appId = [NSString stringWithUTF8String:appStoreId.c_str()];;
// check SKStoreProductViewController API exist or not
if(NSClassFromString(@"SKStoreProductViewController")) {
SKStoreProductViewController *storeController = [[SKStoreProductViewController alloc] init];
storeController.delegate = self;
NSDictionary *productParameters = @{ SKStoreProductParameterITunesItemIdentifier : appId };
[storeController loadProductWithParameters:productParameters completionBlock:^(BOOL result, NSError *error) {
if (result) {
[self presentViewController:storeController animated:YES completion:nil];
} else {
[[[UIAlertView alloc] initWithTitle:@"Error Occur"
message:@"Error to open App Store."
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles: nil] show];
}
}];
[storeController release];
} else {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:appUrlStatic]];
}
}
謝謝你就是我想要的!如果你添加這個代碼,也許它會更好。 [self presentViewController:storeController animated:YES completion:nil]; // ^^; –
如果你不想要,塊取決於需求,那麼你可以使用nil。你可以爲它+1並批准我的答案嗎? – Hindu