1

I want to display an activityIndicator when the user presses the iTunes buy button to finally purchase a subscription. There is a bit of time processing the purchase and soon as it's done I want to clear the activityIndicator.

I've tried different solutions with one of them using applicationWillResignActive to detect the iTunes pop up and this is detected right where user is is asked to type in the password. I have also posted a notification when products are requested but still the same thing. Is there a way to know when the iTunes buy button is pressed. Below is my code.

extension Notification.Name {
    public static let AppDelegatePurchasesIsProccessing = NSNotification.Name("AppDelegatePurchasesIsProccessing")
}

func applicationWillResignActive(_ application: UIApplication) {
        NotificationCenter.default.post(name: .AppDelegatePurchasesIsProccessing, object: self)
      }
}

Overlay that is displayed to make purchases

override func viewWillAppear(_ animated: Bool) {
      super.viewWillAppear(animated)
      self.notifyForUserIsPurchasingProduct {
          self.activityIndicator.startAnimating()
     }
 }

override func viewWillDisappear(_ animated: Bool) {
      super.viewWillDisappear(animated)
      self.notifyForUserHasPurchasedProduct {
          self.activityIndicator.stopAnimating()
          self.dismiss(animated: true)
     }
}
func notifyForUserHasPurchasedProduct(_ action: @escaping () -> Void) {
     NotificationCenter.default.addObserver(forName: .AppDelegateUserHasPurchasedProductNotification, object: nil, queue: nil) { (_) in
          action()
    }
}

func notifyForUserIsPurchasingProduct(_ action: @escaping () -> Void) {
      NotificationCenter.default.addObserver(forName: .AppDelegatePurchasesIsProccessing, object: nil, queue: nil) { (_) in
          action()
     }
}

3
  • Can't you just start the activity indicator when the buy button is pressed? Whatever action is triggering the purchase should trigger the activity indicator. Commented Apr 16, 2019 at 16:04
  • Yah I've resorted to that. Looks like there isn't a way to detect when the buy button is pressed Commented Apr 17, 2019 at 7:35
  • You should see the transaction on the SKPaymentQueue after they buy (or cancel) you can stop your activity indicator there. Commented Apr 17, 2019 at 14:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.