【问题标题】:Get Apple UIAlertController completion when using StoreKit使用 StoreKit 时获取 Apple UIAlertController 完成
【发布时间】:2015-10-12 10:09:01
【问题描述】:
我正在实现一个支付视图控制器,每当 StoreKit 获取一些数据时,我想在其中呈现一个加载视图(微调器)。我在单击“购买”按钮时添加加载视图,并在调用 func productsRequest(request: SKProductsRequest, didReceiveResponse response: SKProductsResponse) 时将其删除。
问题是 loadingView 仍在运行,而“登录 iTunes Store”(以及其他)仍然显示。有什么方法可以获取/覆盖 Apple 生成的 UIAlertControllers 的完成块?
【问题讨论】:
标签:
ios
swift
storekit
uialertcontroller
【解决方案1】:
我可以建议使用MKStoreKit吗?
我在使用 StoreKit 时遇到了问题,但继续使用 MKStoreKit 编写这样的代码。
let notification = NSNotificationCenter.defaultCenter()
func purchase() {
MKStoreKit.sharedKit().initiatePaymentRequestForProductWithIdentifier("YOURIDENTIFIER")
self.notification.addObserverForName(kMKStoreKitProductPurchaseFailedNotification, object: nil, queue: NSOperationQueue()) {
(note) -> Void in
// It failed for some reason
self.hideLoadingView()
}
self.notification.addObserverForName(kMKStoreKitProductPurchasedNotification, object: nil, queue: NSOperationQueue()) {
(note) -> Void in
// It was purchased
self.hideLoadingView()
}
self.notification.addObserverForName(kMKStoreKitProductPurchaseDeferredNotification, object: nil, queue: NSOperationQueue()) {
(note) -> Void in
// It was canceled
self.hideLoadingView()
}
}
func hideLoadingView() {
// Do whatever you need to
}
让事情变得更容易管理