0

I'm implementing a payment ViewController, where I want to present a loading view (spinner), whenever StoreKit is fetching some data. I add the loading view when the "Purchase" button is clicked, and removes it when func productsRequest(request: SKProductsRequest, didReceiveResponse response: SKProductsResponse) is called.

The problem is that the loadingView is still running while the "Sign In to iTunes Store" (among others) is still shown. Is there any way that I can get/override the completion block of the Apple generated UIAlertControllers?

halfer
  • 19,824
  • 17
  • 99
  • 186
Nikolaj Simonsen
  • 1,650
  • 3
  • 18
  • 34

1 Answers1

0

May I suggest using MKStoreKit?

I had issues with StoreKit, but moved on to code like this with 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
}

Made things much easier to manage

Naoto Ida
  • 1,275
  • 1
  • 14
  • 29