UrbanApps / Armchair

A simple yet powerful App Review Manager for iOS and OSX in Swift
MIT License
1.2k stars 137 forks source link

AlertController not showing up with warning: Attempt to present UIAlertController on UINavigationController whose view is not in the window hierarchy! #120

Open sandeepbol opened 6 years ago

sandeepbol commented 6 years ago

I am notifying Armchair of a significant event from a callback of a async request as follows

func onTransactionCompleted(status: TransactionStatus) {
  if (status == .success) {
      DispatchQueue.main.async {
        Armchair.userDidSignificantEvent(true)
      }
  }
}

but Alertcontroller is not shown and debugger shows

warning: Attempt to present UIAlertController on UINavigationController whose view is not in the window hierarchy!

sandeepbol commented 6 years ago

I got around the issue by moving Armchair.userDidSignificantEvent(true) to viewDidAppear:

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        if canShowRatingPrompt {
            Armchair.userDidSignificantEvent(true)
            canShowRatingPrompt = false
        }
    }

But will be happy to hear what might be more clean and best approach.