iOS APP之间跳转

442 阅读1分钟

App之间跳转有两种

1.第一种。跳出App,打开AppStore,使用AppStore预览。

- (void)click1 {
    NSURL *url = [NSURL URLWithString:@"itms-apps://itunes.apple.com/app/id1142110895"];
    if (@available(iOS 10.0, *)){
         [[UIApplication sharedApplication]openURL:url options:@{UIApplicationOpenURLOptionsSourceApplicationKey:@YES} completionHandler:^(BOOL success) {
             if (success) {
                 NSLog(@"10以后可以跳转url");
             }else{
                 NSLog(@"10以后不可以跳转url");
             }
         }];
     }else{
         BOOL success = [[UIApplication sharedApplication]openURL:url];
         if (success) {
              NSLog(@"10以前可以跳转url");
         }else{
              NSLog(@"10以前不可以跳转url");
         }
     }
 }

1.第二种。在自家的App内弹出。(类似某音推广游戏)

//2:实现代理SKStoreProductViewControllerDelegate
SKStoreProductViewController *storeProductViewContorller = [[SKStoreProductViewController alloc] init];
storeProductViewContorller.delegate = self;
//加载一个新的视图展示
[storeProductViewContorller loadProductWithParameters: @{SKStoreProductParameterITunesItemIdentifier : @"1142110895"} completionBlock:^(BOOL result, NSError *error) {
    //回调
    if(error){
         NSLog(@"错误%@",error);
    }else{
        //应用界面
        [self presentViewController:storeProductViewContorller animated:YES completion:nil];
    }
}];

实现协议(取消按钮监听)回调

- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController{
    [self dismissViewControllerAnimated:YES completion:nil];
}