如何检测应用内购买过程是否正在进行?

问题描述

在Swift中是否可以检测用户是否正在购买商品?该过程通常耗时约15-20秒,并显示3-4种不同的警报(Apple ID的警报键入密码,用于确认购买,是否已成功购买的信息等)。
我的问题是,只要该应用即将启用,就会显示ads(OpenAd),因此,当他尝试购买高级帐户以删除广告时,看到广告确实是很糟糕的用户体验...
这是我向他们展示(AppDelegate)的代码部分:

func applicationDidBecomeActive(_ application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was prevIoUsly in the background,optionally refresh the user interface.
        tryToPresentAd()
    }

以下是进行演示的方法(也用AppDelegate编写):

func tryToPresentAd() {
            let ad: GADAppOpenAd? = self.appOpenAd
            self.appOpenAd = nil
            
            if ad != nil {
                guard let rootController = self.window?.rootViewController else { return }
                ad?.present(fromrootViewController: rootController)
            } else {
                requestAppOpenAd()
            }
        }

func requestAppOpenAd() {
            self.appOpenAd = nil
            GADAppOpenAd.load(withAdUnitID: Bundle.getValue(forKey: "xyzID"),request: GADRequest(),orientation: .portrait) { (ad,error) in
                if error != nil {
                    debugPrint("Failed to load app open ad",error as Any)
                } else {
                    self.appOpenAd = ad
                }
            }
        }

有什么方法可以检测到它?也许像放一些标志或东西,或者苹果有某种内置的方法来检测它?谢谢。

解决方法

也许您可以尝试创建一个布尔值,该布尔值在用户决定购买某物时会变为true,并检查布尔值是否为false以便tryToPresentAd()。