iOS 开发应用内跳转到App Store

    xiaoxiao2022-07-04  157

     

    1.离开本应用跳转到App Store

     

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

     

    2.不离开本应用,应用内跳转到App Store

    导入头文件 #import <StoreKit/StoreKit.h>

    遵循代理协议 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"); }]; }

     

    最新回复(0)