2

I was integrating the adcolony video ads in my iphone game. When displaying the ad we are getting the error

" ADCOLONY 2.0.1 [* ERROR *] AdColony has ads, but could not display them. AdColony was unable to find the currently visible UIViewController for your app. Please ensure that your key UIWindow has a rootViewController."

When i checked the code in appdelegate we had already set the rootviewcontroller of UIWindow like this :

self.viewController_ipad = [[ViewController_ipad alloc] initWithNibName:nil bundle:nil] ; window.rootViewController = self.viewController_ipad; [window makeKeyAndVisible];

Still i am getting this error. Please guide us in right direction to solve this problem ?

Thanks in advance!

Abdullah Shafique
  • 6,878
  • 8
  • 35
  • 70
Tornado
  • 1,069
  • 12
  • 28

1 Answers1

2

I got the reply by Adcolony Engineers :

AdColony finds the visible UIViewController being shown in your app's key UIWindow, and then pushes a modal view controller, which is used to display ads, on top. Once the ad is complete, our SDK pops the modal view controller off, leaving your app in the state it was previously. You will encounter the error you mentioned if our SDK gets a nil value for your app's topmost view controller.

I can tell you that, in the past, I've seen this problem occur if a developer uses a button in an UIAlertView to trigger an AdColony video ad. If this is the case, and you are triggering videos from a UIAlertView or a UIActionSheet, we highly recommend making sure they are fully dismissed before you make the call to play a video.

I'd like to get this sorted out as quickly as possible for you. Is there anyway you could send us a stripped down version of your code that will reproduce the problem? If that's not a possibility, I would recommend pasting the following code in the place where you are trying to play a video, and using a debugger to figure out where you are getting a nil value.

UIWindow* window = [UIApplication sharedApplication].keyWindow;
UIViewController* rootViewController = [window rootViewController];
[self getVisibleViewControllerChild:rootViewController];

And here's the method we use, getVisibleViewControllerChild:

- (UIViewController*)getVisibleViewControllerChild:(UIViewController*)viewController {

UIViewController* visibleViewController = nil;

if(!viewController) {
return nil;
}

if ([viewController isKindOfClass:[UINavigationController class]]) {
UINavigationController* navigationController = (UINavigationController*)viewController;
viewController = navigationController.visibleViewController;
}

while (visibleViewController == nil) {

if (viewController.modalViewController == nil) {
visibleViewController = viewController;
} else {

if ([viewController.modalViewController isKindOfClass:[UINavigationController class]]) {
UINavigationController *navigationController = (UINavigationController *)viewController.modalViewController;
viewController = navigationController.visibleViewController;
} else {
viewController = viewController.modalViewController;
}
}

}

return visibleViewController;
}

Hope this helps other people who get the similar problem.

Divyu
  • 1,325
  • 9
  • 21
Tornado
  • 1,069
  • 12
  • 28
  • Hi,do apple approve the apps that use adcolony sdk? – iosDev_1205 Jul 05 '14 at 07:05
  • I've the same problem. I'm using UIAlertView, I don't know how to dismiss the UIAlertView before playing adcolony video. How to solve it? I've to wait for 2 seconds to let the UIalertView dismiss then play the video, otherwise:`Warning: Attempt to present <_UIModalItemsPresentingViewController: 0x1d0b09b0> on <_UIModalItemAppViewController: 0x1d073750> which is already presenting <_UIModalItemsPresentingViewController: 0x1d072df0>` – Gank Sep 06 '14 at 14:30
  • [alert dismissWithClickedButtonIndex:-1 animated:NO]; solved by it – Gank Sep 06 '14 at 14:53
  • [alert dismissWithClickedButtonIndex:-1 animated:NO]; did not alone work for me on iOS 8 devices. I had to then delay showing the ad a second while the dialog disappeared. – Brian Teschke Nov 28 '14 at 15:55