In my app I am using some ads SDK's. In many of them, when a user clicks on ad to download an app, the SDK using SKStoreProductViewController to enable the user to get the app. The store page is opened as modal view.
Is there any way to detect that SKStoreProductViewController was opened?
I tried to do so by counting the amount of viewcontrollers opened in specific moment in the app:
[[[[[UIApplication sharedApplication] delegate] window] rootViewController] childViewControllers]
Didn't give me what I wanted.
I also tried this:
[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];
}
}
}
But didn't find it...
Maybe someone have better idea ?
I've found the answer:
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];
}
}
}