【问题标题】:iOS - detect SKStoreProductViewController was openediOS - 检测 SKStoreProductViewController 已打开
【发布时间】:2014-12-09 12:50:10
【问题描述】:

在我的应用中,我使用了一些广告 SDK。 在其中许多中,当用户点击广告下载应用程序时,SDK 使用 SKStoreProductViewController 使用户能够获取应用程序。商店页面以模态视图打开。

有什么方法可以检测到 SKStoreProductViewController 被打开了吗?

我尝试通过计算应用中特定时刻打开的视图控制器数量来做到这一点:

 [[[[[UIApplication sharedApplication] delegate] window] rootViewController] childViewControllers]

没有给我想要的。

我也试过这个:

     [self checkWithView:[[[UIApplication sharedApplication] delegate] window]];


     -(void)checkWithView:(id)view
     {
         NSArray *views = [view subviews];
         for (id view in views) {
             if ([view isKindOfClass:[SKStoreProductViewController class]]){
                 NSLog(@"Bingo!");
             }
             else{
                 [self checkWithView:view];
             }
        }
     }

但是没找到……

也许有人有更好的主意?

【问题讨论】:

    标签: ios app-store ads


    【解决方案1】:

    我找到了答案:

    UIViewController *vc = [[[UIApplication sharedApplication] delegate] window].rootViewController.presentedViewController;
    
    [self checkWithViewController:vc];
    
    
     -(void)checkWithViewController:(UIViewController *)viewController
     {
        if(viewController){
           if ([viewController isKindOfClass:[SKStoreProductViewController class]]){
                NSLog(@"Bingo!");
           }
           else{
               [self checkWithView:viewController.presentedViewController];
           }
        }
     }
    

    【讨论】:

      猜你喜欢
      • 2013-08-07
      • 2016-02-20
      • 2021-01-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-12
      • 1970-01-01
      相关资源
      最近更新 更多