iOS - 检测 SKStoreProductViewController 被打开

标签 ios app-store ads

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

有什么方法可以检测到 SKStoreProductViewController 已打开?

我试图通过计算应用程序中特定时刻打开的 View Controller 的数量来做到这一点:

 [[[[[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];
             }
        }
     }

但是没找到...

也许有人有更好的主意?

最佳答案

我找到了答案:

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];
       }
    }
 }

关于iOS - 检测 SKStoreProductViewController 被打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27379375/

相关文章:

ios - 核心数据。索引和索引之间有什么区别?

ios - 提交到 AppStore 时出现奇怪的错误

iphone - 如果我在 iTunes Connect 中输入 "Reject Binary"来提交更新的二进制文件,我会失去排队的位置吗?

android - admob粗定位能提高多少收入?

javascript:移动设备上的插页式广告 - 您如何处理缩放?

adsense - 谷歌 Adsense : can you really get approved for Adsense program with a site like this?

ios - CAGradientLayer 超出 UILabel 的框架

iOS:在 Objective-C 中为 iOS App 创建服务器

iOS - 核心数据自动生成模型 - 无法识别的选择器