根据appid跳到App Store某个APP的详情页

时间:2021-03-29 23:33:28

需求

本手机是否装了某个APP 示例百度appid 382201985  scheme BaiduSSO://

1.是,直接打开百度APP

2.否,跳到App Store百度APP的详情页

NSString *aScheme = @"BaiduSSO://";

NSString *aAppleId = @"382201985";

NSURL*aAppUrl = [NSURL URLWithString:[NSString stringWithFormat:@"%@://", aScheme]];

//打开某个APP

[[UIApplication sharedApplication] openURL:aAppUrl options:@{} completionHandler:^(BOOL success) {

if (!success) {

//跳到App Store某个APP的详情页

[self showAppStoreWithAppId:aAppleId];

}

}];

导入头文件

#import <StoreKit/StoreKit.h>

加代理

SKStoreProductViewControllerDelegate

-(void)showAppStoreWithAppId:(NSString *)appId

{

SKStoreProductViewController *appStore = [[SKStoreProductViewController alloc] init];

appStore.delegate = self;

[appStore loadProductWithParameters:@{SKStoreProductParameterITunesItemIdentifier:appId} completionBlock:^(BOOL result, NSError * _Nullable error) {

if (error) {

NSLog(@"错误 %@",error);

} else {

}

}];

[self presentViewController:appStore animated:YES completion:nil];

}

- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController

{

[viewController dismissViewControllerAnimated:YES completion:nil];

}