IAP Ads Removed Pref Error
HI All,
I have implemented IAP in my game to "RemoveAds", i used Unity IAP and the sample code (Below) this is not the full code but the section that requires the function, in my LevelManager script i have created bool set it to true and i check it before an ad is played, like so, PlayerPrefs.GetInt ("RemovedAds", 0) == 0) ..... the whole thing works, i send to alpha testers and they purchase the item but the ads still play, any ideas why?.
// Or ... a non-consumable product has been purchased by this user. else if (String.Equals(args.purchasedProduct.definition.id, kProductIDNonConsumable, StringComparison.Ordinal)) { Debug.Log(string.Format("ProcessPurchase: PASS. Product: '{0}'", args.purchasedProduct.definition.id)); // TODO: The non-consumable item has been successfully purchased, grant this item to the player. PlayerPrefs.SetInt("AdsRemoved", 1); PlayerPrefs.Save(); Debug.Log("Purchase Complete"); }
#endif
if (Advertisement.isSupported && !Advertisement.isInitialized && PlayerPrefs.GetInt("AdsRemoved", 0) == 0)
{
Advertisement.Initialize(gameId, enableTest$$anonymous$$ode);
}
}
void ShowAd()
{
if (Advertisement.IsReady() && currentScene >= adInterval && currentScene % adInterval == 1 && PlayerPrefs.GetInt("AdsRemoved", 0) == 0)
{
Advertisement.Show();
}
}
#endregion
Answer by Naphier · Nov 14, 2016 at 10:41 PM
What's calling ShowAds? ShowAds should also be checking to see if that PlayerPref has been set.
Apologies @Naphier,
I have only just seen this, i will make some changes and give it a test, let you know soon as.
Thanks.
@Naphier, I have added the check before showing ads like so,
If (PlayerPrefs.GetInt("AdsRemoved" , 0) == 0) ShowAds();
The problem i am having is that now the ads in the game are not working, it is defiantly to do with the check in the ShowAds(); section because as soon as i remove this they work again, any ideas?
Cheers.
Sounds like you have that value set to 1 in the player prefs. Obviously, you'll need to reset the value to test. If the app is on a mobile device then clear the app data or uninstall and reinstall it. If it is in Windows then call PlayerPrefs.DeleteAll() and that will clear them out. To learn more about player prefs and data saving check out my blog (http://blog.naplandgames.com).
Beyond that try some more debugging.
Cheers!
Thanks for the info i will see what i can do and let you know, the app is for mobile, Android and IOS, check it out if you like. :)
Changed a bit since the versions below, bug fixes and Design etc. I wont update until i have IAP added.
Check out my game https://play.google.com/store/apps/details?id=com.HappyChappyGames.Bounce_E Free on Google Play Store Now!!!
Now Available for IOS!! Check it out here!! https://itunes.apple.com/gb/app/bounce-e/id1161264369?mt=8
Answer by BrodyDaChappy · Nov 30, 2016 at 09:08 PM
Hi @Naphier,
I have figured it out, i did an alpha test build of my latest changes and everything done as it should, but i do want to double check it with another tester who i am waiting for now.
Based on your answers/comments i figured out what i needed to try and it worked smoothly as it should :).
Adding a "Remove Ads" option took me a good month or so now, glad to finally be over it :).
Cheers.
Anyone else that would like to know how to integrate Unity IAP for "Remove Ads" feel free to e-mail me, e-mail should be on my profile.
Your answer
![](https://koobas.hobune.stream/wayback/20220612100625im_/https://answers.unity.com/themes/thub/images/avi.jpg)