Jump to App Store in iOS development app

 

1. Leave the app and jump to the App Store

 


NSString *url = @"https://itunes.apple.com/app/apple-store/id1457293407?mt=8";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];

 

2. Do not leave the app, jump to the App Store in the app

Import the header file#import <StoreKit/StoreKit.h>

Follow the proxy protocol SKStoreProductViewControllerDelegate

- (void)jumpAppStore {

	NSDictionary *dict = [NSDictionary dictionaryWithObject:@"1457293407" forKey:SKStoreProductParameterITunesItemIdentifier];
	SKStoreProductViewController *vc = [[SKStoreProductViewController alloc] init];
	vc.delegate = self;
//	1.先加载,加载成功再跳转到App Store
	[vc loadProductWithParameters:dict completionBlock:^(BOOL result, NSError * _Nullable error) {
		if(error) {
			NSLog(@"Error:%@",error.userInfo);
		}
		else {
			[self presentViewController:vc animated:YES completion:nil];
		}
	}];
		//	2.先跳转到App Store,再加载数据
//	[self presentViewController:vc animated:YES completion:nil];
//	[vc loadProductWithParameters:dict completionBlock:^(BOOL result, NSError * _Nullable error) {
//		if(error) {
//			NSLog(@"Error:%@",error.userInfo);
//		}else {
//		}
//	}];
}


#pragma mark - SKStoreProductViewControllerDelegate

- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController {
	[viewController dismissViewControllerAnimated:YES completion:^{
		NSLog(@"productViewControllerDidFinish");
	}];
}

 

Guess you like

Origin blog.csdn.net/zjpjay/article/details/90444865