AppLovin Ads in Unity3D : onAppLovinEventReceived not fired - ios

I used Applovin fullscreen ads in Unity3D iOS game.
Ads are working good. But event listener not fired. I wish to track fail event call.
public static void StartApplovin ()
{
AppLovin.SetSdkKey("My_SDK_Key");
AppLovin.InitializeSdk();
AppLovin.SetUnityAdListener("ApplovinListener");
}
Here is ApplovinListener.cs class
public class ApplovinListener : MonoBehaviour {
void onAppLovinEventReceived(string ev)
{
Debug.Log ("\n\nonAppLovinEventReceived\n\n");
if(ev.Contains("DISPLAYEDINTER")) {
// An ad was shown. Pause the game.
}
else if(ev.Contains("HIDDENINTER")) {
// Ad ad was closed. Resume the game.
// If you're using PreloadInterstitial/HasPreloadedInterstitial, make a preload call here.
AppLovin.PreloadInterstitial();
}
else if(ev.Contains("LOADEDINTER")) {
// An interstitial ad was successfully loaded.
}
else if(string.Equals(ev, "LOADINTERFAILED")) {
// An interstitial ad failed to load.
GameCenter2.ShowAdmobAds ();
Debug.Log ("\n\n Applovin FAILED\n\n");
}
}
}
When I run, Xcode gives below console log.
SendMessage: object ApplovinListener not found!
How to get onAppLovinEventReceived called ?
UPDATE: I have fixed this problem by creating gameObject
In Unity Manu, Press GameObject->Create Empty
Name it “ApplovinListener”
Now attach script named ApplovinListener to game object. That’s it.

Your ApplovinListener script must be attached to the name of the GameObject that is passed into the AppLovin.SetUnityAdListener function in order for the onAppLovinEventReceived function to be called.
You had this:
AppLovin.SetUnityAdListener("ApplovinListener");
Make sure that there is a GameObject actually named "ApplovinListener". Now, make sure that the ApplovinListener script is attached to it. The onAppLovinEventReceived function should be called after you do this.
To make this easier for you, I recommend you do this instead:
AppLovin.SetUnityAdListener(yourGameObject.name);
then attach the ApplovinListener script to that GameObject you referenced above.

Related

iOS requestTrackingAuthorization callback is not on the main thread

The iOS ATT Alert needs to be shown on startup before an app starts, so the remaining app code needs to be run in the completion handler (eg initialising advert code and starting the main game).
However, this crashes because the completion handler callback is not on the main thread (after the alert is actually shown and Allow or Ask App Not to Track is selected).
In iOS (Xamarin C# code):
public override void OnActivated(UIApplication application) // RequestTrackingAuthorization must be called when app is Active
{
if (!this.shownAlert)
{
this.shownAlert=true;
Debug.WriteLine("1) ThreadId={0}", Environment.CurrentManagedThreadId); // ThreadId=1
ATTrackingManager.RequestTrackingAuthorization(delegate (ATTrackingManagerAuthorizationStatus trackingManagerAuthorizationStatus)
{
Debug.WriteLine("2) ThreadId={0}", Environment.CurrentManagedThreadId); // ThreadId=7
});
}
}
Prints:
1) ThreadId=1
2) ThreadId=7
And the similarly in Unity:
Debug.WriteLine("1) ThreadId={0}", Environment.CurrentManagedThreadId); // ThreadId=1
ATTrackingStatusBinding.RequestAuthorizationTracking(delegate (int status)
{
Debug.WriteLine("2) ThreadId={0}", Environment.CurrentManagedThreadId); // ThreadId=4
});
This seems like a bug to me. So how do all the apps and games out there get this to work? Somehow switch to the main thread in the callback? I don’t see any examples of this.

Unity Ads Showing Only in Editor

I'm trying to implement Unity Ads on my game that I'm planning on deploying on iOS, but for some reason they are only appearing in the editor (where it says "Everything Seems to be Working!") but every time I build to my iPhone 5s, the ads don't pop up.
Here is my script (to activate it I just attached it to a game-object in my scene):
static int loadCount = 0;
void Start()
{
if (loadCount % 3 == 0) // only show ad every third time
{
ShowAd ();
}
loadCount++;
}
public void ShowAd()
{
if (Advertisement.IsReady())
{
Advertisement.Show();
}
}
Any help is appreciated!

How to hide amazon ads in unity

So I integrated amazon mobile ads into my unity/ios project. I have it all working to where I hide the ads every time a scene changes. Every time I open a scene, the ad shows. So it's all working fine except when you change scenes really quickly. I don't want ads in the main game as it obstructs the view of the users. Every time you get to the retry scene, if you quickly switch from that scene right before an ad loads, that ad will get stuck on the next scene which makes another ad show on top of it. Every time a scene changes it should be hiding the ad not matter how fast you change scenes. Is there any way to make sure it hides the ad if an ad is shown? I'm using the code below:
void Start() {
mobileAds = AmazonMobileAdsImpl.Instance;
ApplicationKey key = new ApplicationKey();
key.StringValue = iosKey;
mobileAds.SetApplicationKey(key);
ShouldEnable enable = new ShouldEnable();
enable.BooleanValue = true;
mobileAds.EnableTesting(enable);
mobileAds.EnableLogging(enable);
Placement placement = new Placement();
placement.Dock = Dock.BOTTOM;
placement.HorizontalAlign = HorizontalAlign.CENTER;
placement.AdFit = AdFit.FIT_AD_SIZE;
response = mobileAds.CreateFloatingBannerAd(placement);
string adType = response.AdType.ToString();
long identifer = response.Identifier;
newResponse = mobileAds.LoadAndShowFloatingBannerAd(response);
bool loadingStarted = newResponse.BooleanValue;
}
void OnDestroy() {
mobileAds.CloseFloatingBannerAd(response);
response = null;
mobileAds = null;
newResponse = null;
}
When did you download the Unity Plugin? There were some issues in an early version of the plugin that this sounds like (the whole, one ad loading over top of another thing). If you have not updated it recently, try downloading the latest version from Amazon and see if the issue still occurs.
The close ad API
mobileAds.CloseFloatingBannerAd(response);
will only work if the ad is already loaded. You need to register for the ad loaded event. If the scene is destroyed, then you would close the ad when the ad loaded event tiggers.
You can register for AdLoaded event as follows, Documentation
using com.amazon.mas.cpt.ads;
bool sceneDestroyed = false; //tracks if scene is destroyed
//Obtain object used to interact with the plugin
IAmazonMobileAds mobileAds = AmazonMobileAdsImpl.Instance;
// Define event handler
private void EventHandler(Ad args)
{
if (sceneDestroyed)
{
mobileAds.CloseFloatingBannerAd(response);
}
else
{
//Do some other job
}
}
//Register for an event
mobileAds.AddAdLoadedListener(EventHandler);
void OnDestroy()
{
sceneDestroyed = true;
}

How can I find out which network an ad is from in AdMob Mediation?

Is there a way to determine which network a specific ad is from when using AdMob Mediation? For example, within the interstitialDidReceiveAd:(GADInterstitial *)ad method, does the variable ad have a specific property that contains the name of the ad network that the ad is from? I want to use the specific ad network to manipulate how my app works in terms of how to properly dismiss the view.
On Android you can do something like this:
adView.setAdListener(new AdListener() {
#Override
public void onAdLoaded() {
super.onAdLoaded();
Log.i("TEST", "onAdLoaded: " + adView.getMediationAdapterClassName());
}
});
Which will return something like:
I/TEST: onAdLoaded: com.mobfox.adapter.MobFoxAdapter
I'm using Xamarin.iOS so the following is in C#, but maybe it'll help you. I've used this code to determine whether the ad is from iAd or from AdMob. I wrote this quickly just for debugging purposes and this method will only tell you if the ad is from AdMob or something else, which in my case was always iAd.
var property = view.MediatedAdView.GetType().GetProperty("AdUnitID");
string adType;
if (property != null && property.GetValue(view.MediatedAdView) != null)
{
adType = "AdMob";
}
else
{
adType = "iAd";
}
Unfortunately the answer is no.
You can use ad.adNetworkClassName.
Example values I'm getting GADMAdapterGoogleAdMobAds, GADMAdapterUnity.
Works for both interstitial and rewarded video ads.
You can check the actual class being used in the delegate. The code in Swift:
func interstitialDidReceiveAd(_ interstitial: GADInterstitial) {
print("Interstitial adapter class name: \(interstitial.responseInfo.adNetworkClassName)")
}

Unable to close screen after the email attachment download is completed

I am using AttachmentDownloadManager class download method to download the email attachments to the device.I am displaying a progress screen while the attachments gets downloaded to device.In the downloadCompleted() event listener method, I am trying to stop/close the progress screen but unable to do so.
Below is the code snippet:
attachmentDownloadMngr = new AttachmentDownloadManager();
attachmentDownloadMngr.download(attachmentBodyPart, null, new IGAEmailAttachmentListener(this));
Below are DownloadProgressListener event listener methods:
public void updateProgress(Object element, int current, int total)
{
synchronized(UiApplication.getEventLock())
{
Ui.getUiEngine().pushGlobalScreen(progressScreen,1,UiEngine.GLOBAL_QUEUE);
}
}
public void downloadCompleted(Object element)
{
synchronized(UiApplication.getEventLock())
{
Ui.getUiEngine().popScreen(progressScreen);
}
}
public void downloadCancelled(Object element)
{
}
progressScreen is instance of PopupScreen where I am displaying a guagefield. The progress screen does not get any events even after the attachment download is completed.
Please help me to solve this issue.
You seem to be pushing a globalscreen every time you get a callback to updateprogress() . I wouldn't do it. I would rather push the globalscreen with the gaugefield when I start the download, and then set the value of gaugefield using gaugeField.setValue(value).
the way you are doing it would mean, the event thread pushes too many screens on to the stack, and I guess it would throw a run time exception and kill your app.

Resources