我正在尝试为统一移动应用程序实现删除广告功能,我还没有将 IAP 服务与 google play 集成,但我只是想弄清楚逻辑并使其首先在测试环境中工作。我成功地显示了一个底部屏幕广告横幅,当用户登录时,在他的个人资料屏幕上有一个删除广告的按钮,OnClick 数据库中名称“订阅”的用户属性设置为 true,我删除了广告按钮和隐藏广告横幅,所以在下次登录时,我实现了一个检查用户订阅的功能,因此如果用户订阅了,则不显示删除广告按钮和广告横幅。此协程在用户登录时运行,并且在订阅用户登录时不显示删除广告按钮,
我正在使用 Unity Ads 来显示广告横幅。
private IEnumerator CheckSubscription()
{
var DBTask = DBreference.Child("users").Child(User.UserId).GetValueAsync();
yield return new WaitUntil(predicate: () => DBTask.IsCompleted);
if(DBTask.Exception != null)
{
Debug.LogWarning(message: $"Failed to retrieve user subscirption status");
}
else
{
DataSnapshot snapshot = DBTask.Result;
var isSubscribed = snapshot.Child("subscription").Value.ToString();
if(isSubscribed == "true")
{
UIManager.instance.RemoveAds();
AdDisplay.instance.showAds = false; //Console error on this line of code
}
else
{
AdDisplay.instance.showAds = true;
}
}
}