1. 程式人生 > 實用技巧 >根據appid跳到App Store某個APP的詳情頁

根據appid跳到App Store某個APP的詳情頁

需求

本手機是否裝了某個APP 示例百度appid 382201985 schemeBaiduSSO://

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的詳情頁

[selfshowAppStoreWithAppId: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 {

}

}];

[selfpresentViewController:appStore animated:YES

completion:nil];

}

- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController

{

[viewController dismissViewControllerAnimated:YES completion:nil];

}