我们正在实现 Apple 的新“Promoted In-App Purchases”系统,允许用户单击 Apple App Store 内的“购买”按钮,从而触发购买 IAP。
系统调用应用程序来实现 SKPaymentTransactionObserver
的 paymentQueue: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/