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.