【发布时间】:2021-03-03 19:16:07
【问题描述】:
我正在尝试为统一移动应用程序实现删除广告功能,我尚未将 IAP 服务与 google play 集成,但我只是想弄清楚逻辑并使其首先在测试环境中工作。我成功地显示了一个底部屏幕广告横幅,当用户登录时,在他的个人资料屏幕上有一个删除广告的按钮,OnClick 数据库中名称“订阅”的用户属性设置为 true,我删除了广告按钮和隐藏广告横幅,所以在下次登录时,我实现了一个检查用户订阅的功能,因此如果用户订阅了,则不显示删除广告按钮和广告横幅。这个协程在用户登录和订阅用户登录时运行,删除广告按钮不显示,但广告横幅仍然打开,我在调用 AdDisplay 实例的 HideBanner 函数的行上收到 NullReferenceException 错误。
我正在使用 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;
}
}
}
【问题讨论】:
标签: c# unity3d in-app-purchase unityads