gpt4 book ai didi

ios - 向 AppDelegate 发送消息不适用于应用内购买

转载 作者:行者123 更新时间:2023-11-29 02:39:29 25 4
gpt4 key购买 nike

我正在尝试在完成已设置的 IAP 后删除 AdMob 横幅。据我所知,IAP 设置正确,由于某种原因我遇到的问题是当我在用户完成交易后尝试隐藏广告时,广告不会隐藏。 NSLog 显示,但广告不隐藏。但是,我可以从我程序中的不同方法发送相同的消息,它会很好地隐藏广告。

希望我可以用这段代码更容易地解释它:

我试图像这样隐藏它:

购买交易时:

        case SKPaymentTransactionStatePurchased:               
[self provideContent:transaction.payment.productIdentifier];
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
NSLog(@"Transaction state -> Purchased");
break;

provideContent 方法:

-(void)provideContent:(NSString *)productIdentifer
{
if ([productIdentifer isEqualToString:@"product id here"]) {
AppController *app = (AppController*) [[UIApplication sharedApplication] delegate];
[app hideBannerApp];
}
}

现在在 appdelegate 中:

-(void)hideBannerApp
{
NSLog(@"Hidden banner");
[topBanner removeFromSuperview];
[[NSUserDefaults standardUserDefaults]setBool:areAdsRemoved forKey:@"areAdsRemoved"];
}

出于某种原因,这并没有隐藏广告。 NSLog 显示在 xcode 中,但广告未被删除。

但是,当我从不同的方法调用 [app hideBannerApp] 时,它工作得很好。

例子:

-(void)tapButton
{
if ([productIdentifer isEqualToString:@"product id here"]) {
AppController *app = (AppController*) [[UIApplication sharedApplication] delegate];
[app hideBannerApp];
}

因此,如果我有一个链接到此方法的按钮,它会删除广告并且它会起作用。那么,当我执行完全相同的操作但使用应用内购买时,为什么它不起作用?

最佳答案

横幅 View 是从应用程序委托(delegate)方法 didBecomeActive 添加的 - 此方法可能会在应用程序的生命周期内执行多次,从而导致添加多个横幅 View ,一个接一个。只有最顶层的 View 被删除。

横幅添加代码已移至 didFinishLaunching,这解决了问题

关于ios - 向 AppDelegate 发送消息不适用于应用内购买,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25964087/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com