0
votes

I am new in swift and I am Implementing Cash Free Api Whose process is like this

https://dev.cashfree.com/payment-gateway/integrations/mobile-integration/ios

But I am facing problem while presenting CFViewController it is showing warning

Attempt to present <CFSDK.CFViewController> on <UINavigationController> whose view is not in the window hierarchy!

My code is like this

CFPaymentService().doWebCheckoutPayment(
                        params: self.getPaymentParams(),
                        env: "PROD",
                        callback: self)

While Parameter are

func getPaymentParams() -> Dictionary<String, Any> {
        return [
            "orderId": OrderIdForCashFree,
            "appId": CashFreeAPIKeyFromServer,
            "tokenData" : cftoken,
            "orderAmount": AmountExpectedforServer,
            "customerName": customerNameCashFree,
            "orderNote": orderNoteCashFree,
            "orderCurrency": "INR",
            "customerPhone": customerPhoneCashFree,
            "customerEmail": customerEmailCashFree,
            "notifyUrl": ""
        ]
    }
    

Please Help!

1

1 Answers

0
votes

The warning reads better like this -

Attempt to present <CFSDK.CFViewController> 
on <UINavigationController>
whose view is not in the window hierarchy!

Seems like you are calling this method way too early - maybe in viewDidLoad()

CFPaymentService().doWebCheckoutPayment(
    params: self.getPaymentParams(),
    env: "PROD",
    callback: self
)

If the view is not properly set up yet, you will receive this warning from UIKit. What you can do is -

  1. Initiate this call from a button tap. /// Recommended (same as a user would interact with it in the app)
  2. Delay the call by some time say 0.5 seconds or 1 second. /// Lazy - for testing purpose only

Both of these will make sure that view has had enough time to show up (before the call is initiated) and the warning will go away.