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



Swift中是否可以检测用户是否在购买东西?该过程通常需要15-20秒,并显示3-4个不同的警报(警报键入Apple ID的密码、确认购买、是否成功购买等信息(。
我的问题是,每当应用程序即将激活时,都会显示广告(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
}
}
}

有什么方法可以检测到它吗?也许是放一些标志之类的,或者苹果有一些内置的方法来检测它?谢谢

也许您可以尝试创建一个bool,每当用户决定购买某件东西时,该bool就会变为true,并检查该bool是否为false,以便尝试ToPresentAd((。

最新更新