0

I'm attempting to create a new View Controller for displaying rewarded videos to users using either UnityAds and Vungle (depending on which is available).

After a Vungle video view, the VungleSDKDelegate will call vungleSDKwillCloseAdWithViewInfo which I have implemented as such:

- (void)vungleSDKwillCloseAdWithViewInfo:(NSDictionary *)viewInfo willPresentProductSheet:(BOOL)willPresentProductSheet {
    NSLog(@"vungleSDKwillCloseAdWithViewInfo");

    [self finishVideoView];
}

And finishVideoView as:

- (void) finishVideoView {
    NSLog(@"finishVideoView");
    [self dismissViewControllerAnimated:YES completion:nil];
}

This works great, when it's done, the view controller is dismissed and the app resumes. However, when I attempt to do this method in Unity's UnityAdsDelegate's method unityAdsDidFinish, the view controller just hangs out there and never dismisses.

- (void)unityAdsDidFinish:(NSString *)placementId withFinishState:(UnityAdsFinishState)state{
    NSLog(@"unityAdsDidFinish");

    [self finishVideoView];
}

Any ideas why? It seems that the unityAdsDidFinish callback happens right after I hit the x at the top of the finished video.

I thought it might be a timing issue so I also tried doing: [self performSelector:@selector(finishVideoView) withObject:nil afterDelay:1.0];

But that does not seem to help either.

Tom Hammond
  • 5,842
  • 12
  • 52
  • 95
  • have you checked if the `unityAdsDidFinish:withFinishState:` is invoked on the main queue ? – ystack Feb 24 '17 at 19:10
  • I have not. What's the best way to do that? – Tom Hammond Feb 24 '17 at 19:33
  • a breakpoint in `unityAdsDidFinish:withFinishState:` & looking at the queue name mentioned in the debug navigator or add `NSLog(@"is on main queue: %@", @([NSThread isMainThread]));` – ystack Feb 24 '17 at 19:37
  • Looks like it's on the main thread. – Tom Hammond Feb 24 '17 at 19:45
  • damn! can you check if the `self` object in `unityAdsDidFinish:` is _actually_ the view controller you want to dismiss, adding a `NSLog(@"self object class: %@", [self class])`. Is the class logged the view controller to be dismissed ? – ystack Feb 24 '17 at 20:10

1 Answers1

0

I ended up decided to avoid waiting on the delegate methods and instead implementing finishVideoView in my ViewController's viewWillAppear method. It seems to work now - whenever my view controller appears again, it checks the BOOL to see if a video has played, if so, it finishes the controller.

Tom Hammond
  • 5,842
  • 12
  • 52
  • 95