ios - 推迟来自 App Store 的促销 IAP 请求时显示提醒

标签 ios objective-c swift storekit

我们正在实现 Apple 的新“Promoted In-App Purchases”系统,允许用户单击 Apple App Store 内的“购买”按钮,从而触发购买 IAP。

系统调用应用程序来实现 SKPaymentTransactionObserverpaymentQueue:shouldAddStorePayment:forProduct:委托(delegate)方法,返回一个 bool 值。文档说,

Return true to continue the transaction in your app.

Return false to defer or cancel the transaction.

如果我们只是返回false,用户就会看到我们的应用程序进入前台,然后什么也不会发生。默认情况下,操作系统不会弹出“购买已取消”或类似内容的消息;我想,这将决定权留给了应用程序开发人员。

App Store 推广的 IAP 购买请求可以随时到达,包括当用户处于不应中断的流程中时。从此方法返回 false 是一个完美的情况。当我这样做时,我想向用户显示一条警报消息,解释 UIAlertController 的问题。 .

问题是,我没有可以在我的 paymentQueue:shouldAddStorePayment:forProduct: 中使用的上下文 View Controller 。通常,当我想从 View Controller 内部显示警报时,我会调用 [selfpresentViewController:alertanimated:YEScompletion:nil];,但是 self此委托(delegate)方法是 SKPaymentTransactionObserver,而不是 View Controller ,因此不起作用。

我什至不确定当此委托(delegate)方法触发时是否有一个有保证的事件 View Controller 。据我所知,委托(delegate)方法可能会在 applicationDidBecomeActive 事件之前触发。

paymentQueue:shouldAddStorePayment:forProduct: 返回 false 时显示警报(或任何其他 UI 片段)的最佳方式是什么?

最佳答案

您可以get the application window's root view controller并用它来呈现警报。

Objective-C

id *rootController = [[[[UIApplication sharedApplication]delegate] window] rootViewController];
[rootViewController presentViewController:alertController animated:YES completion:nil];

swift

let appDelegate  = UIApplication.sharedApplication().delegate
let viewController = appDelegate.window!.rootViewController
viewController.presentViewController(alertController, animated: true, completion: nil)

关于ios - 推迟来自 App Store 的促销 IAP 请求时显示提醒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49371981/

相关文章:

swift - sum.swift :29:19: error: cannot find 'CFAbsoluteTimeGetCurrent' in scope

ios - 通过 CNContactViewController 显示时,联系人缺少一些必需的键描述符

ios - UITableView 行选择故障?

iOS 表格 View 单元格未调整大小

ios - uislider 值和变量,Swift 中的标签关联

ios - 让应用程序在后台保持事件状态?

ios - iOS 中本地通知自定义图像图标的大小是多少

ios - CloudKit 可以创建共享私有(private)容器吗?

iphone - 如何在 ios 中减小 PNG 大小以进行电子邮件共享

ios - 带有 CAShapeLayer 的 UIView 不显示 CAGradientLayer