Any way to get reward after the Ads have been finished playing - swift

I want to get reward after Ads have been playing finished, now I will get reward when I close the Ads, I don't want this. Here is my code now, in GADFullScreenContentDelegate:
func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) {
print("Rewarded ad dismissed.")
// function which can get reward.
getReward()
}
I don't know where I have to put this function in, is there any delegate that can know the Ads have been playing finished?

Related

Manage Game Music At Fullscreen Ad Display Time

I have used AppLovin Ad Network to display fullscreen ads within the game.
So I want to turn off game music when fullscreen ad displayed and again turn on game music when fullscreen ad closed by the game player.
I have followed this guideline:
Unity3d Integration
Here we have different listeners available:
Ad Listeners in Unity
I was getting the problem in iOS only in Android automatically game background music gets paused and played again when I closed the fullscreen ad.
Code that I have tested up to now:
public void ShowAppLovinInsterstitial()
{
// Showing utilizing PreloadInterstitial and HasPreloadedInterstitial
if (AppLovin.HasPreloadedInterstitial())
{
// An ad is currently available, so show the interstitial.
AppLovin.ShowInterstitial();
#if UNITY_IOS
SoundManager.Instance.EnableGameMusic(false);
#endif
}
else
{
// No ad is available. Perform failover logic...
AppLovin.PreloadInterstitial();
}
}
void onAppLovinEventReceived(string ev)
{
if (ev.Contains("HIDDENINTER"))
{
// Ad ad was closed. Resume the game.
// If you're using PreloadInterstitial/HasPreloadedInterstitial, make a preload call here.
#if UNITY_IOS
SoundManager.Instance.EnableGameMusic(true);
#endif
AppLovin.PreloadInterstitial();
}
else if (ev.Contains("CLOSEDFULLSCREEN"))
{
#if UNITY_IOS
SoundManager.Instance.EnableGameMusic(true);
#endif
}
}
At present, game music gets paused after fullscreen ad displayed. On fullscreen ad, it was not again started.
Please give me some suggestion for the gameplay music turn on and off during fullscreen ads display.

How to implement AppLovin Reward Video in unity?

I'm trying to add reward video from AppLovin to my application. Interstitial is work perfectly. But Reward video return "LOADREWARDEDFAILED".
Here is the part where I initialize
AppLovin.SetSdkKey(SDKKey);
AppLovin.InitializeSdk();
AppLovin.PreloadInterstitial();
AppLovin.LoadRewardedInterstitial();
AppLovin.SetUnityAdListener("ApplovinListener");
// AppLovin.SetTestAdsEnabled("true");
Here is the part where should be show
if (AppLovin.IsIncentInterstitialReady())
AppLovin.ShowRewardedInterstitial();
else
AppLovin.LoadRewardedInterstitial();
Message from xcode:
LOADREWARDEDFAILED
ApplovinListener:onAppLovinEventReceived(String)

Swift Admob reward based video ad integration and testing

I've successfully been able to integrate both banner ads and image based interstitial ads into my applications with no problems.
I'm considering adding a reward based video ad however I'm not sure if I can simply set up the code as per the interstitial ad but change the adUnitID to that of the rewarded video ad I set up in Admob?
When I do just that the test ad showing an interstitial therefore I can't tell if a video would display.
I'm finding very little guidance to follow online with regard to setting it up this way.
This is what I currently use:
func loadAndShow3() {
let request = GADRequest()
request.testDevices = [kGADSimulatorID, "XXXX"]
myAd = GADInterstitial(adUnitID: "XXXX")
myAd.delegate = self
myAd.load(request)
}
func interstitialDidReceiveAd(_ ad: GADInterstitial) {
if (self.myAd.isReady) {
myAd.present(fromRootViewController: self)
}
func displayAd() {
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "loadAndShow"), object: nil)
}
Your current code would not work. You would have to make a new request for a GADRewardBasedVideoAd instead of the GADRequest(). There is a really good tutorial made by Google at how to do that attached below. If you follow the tutorial it's a rather straight forward solution. Best of luck to you.
Google's tutorial.

RevMobAds - Test video ads not loading?

Ive opted towards RevMob since the iAd network isn't accepting new apps and I'm trying to put a video ad after a round of my game is played like this:
func gameOver() {
RevMobAds.session().fullscreen().loadVideo()
RevMobAds.session().fullscreen().showVideo()
let transition = SKTransition.fadeWithDuration(0.5)
let gameScene = GameOver(size: self.size)
self.view!.presentScene(gameScene, transition: transition)
}
My fullscreen and banner ads are working perfectly, but when I end the game to load the video, I get this in the console with no ad being shown:
[RevMob] Ad received: (200) - 56ba71998e700003764c65b9
Is anyone else having this problem? If so, have you fixed it?
We have changed our documentation, please checkout the updated one here.
What I believe is happening is that you are not saving the fullscreen object. You should create a fullscreen object and save it into a variable:
video = RevMobAds.session().fullscreen()
Then you can load a video ad into the fullscreen object: video!.loadVideo()
And then showVideo on the fullscreen object: video!.showVideo()
Note that loadVideo() is an asynchronous call, so you should either call the methods with completion handlers or extend our delegate classes.
Best regards,

MPMoviePlayerController - Exit, detect movie play and iAd

I have successfully integrated a working movie player with a pre-roll iAd video! Thanks to #Daniel Storm. However, I want information on how to exit the movie when the movie is finished or when the ad is finished. (exit means remove from the view), Also detect if the user has watched the ad. If there is internet connection failure or iAd failure, how can i detect if the pre-roll ad did not play.
I am making a game, and if a user decides to get more coins, that person must watch an ad. If they click on the watch ad button, I want to detect if the ad loaded successfully so that person can get coins after they watch the ad. Once the ad finishes I want to dismiss the MPMoviePlayerController view.
Thank you for your help!
Edit:
Is this correct? :
Is it ok to remove the MPMoviePlayerViewController from the view after it is played like this?: Is this the correct way to remove it?
moviePlayer.playPrerollAdWithCompletionHandler { (error) -> Void in
NSLog("\(error)")
self.moviePlayer.view.removeFromSuperview()
I am supposing this is correct because it removes the view, but is this what apple intends us to do?