【问题标题】:Attempt to present <CFSDK.CFViewController> on <UINavigationController> whose view is not in the window hierarchy尝试在视图不在窗口层次结构中的 <UINavigationController> 上呈现 <CFSDK.CFViewController>
【发布时间】:2021-06-15 06:10:46
【问题描述】:

我是 swift 新手,我正在实施 Cash Free Api,其流程是这样的

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

但我在展示 CFViewController 时遇到问题,它显示警告

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

我的代码是这样的

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

虽然参数是

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": ""
        ]
    }
    

请帮忙!

【问题讨论】:

    标签: swift uiviewcontroller


    【解决方案1】:

    这样的警告读起来更好 -

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

    看来你调用这个方法太早了——也许在viewDidLoad()

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

    如果视图尚未正确设置,您将收到来自UIKit 的警告。你能做的是——

    1. 通过点击按钮发起此呼叫。 /// 推荐(与用户在应用中与之交互相同)
    2. 将呼叫延迟一段时间,例如 0.5 秒1 秒。 /// Lazy - 仅用于测试目的

    这两者都将确保视图有足够的时间显示(在调用开始之前)并且警告会消失。

    【讨论】:

    • 我在单击按钮时调用 API 在 API 响应中我正在调用此代码,我什至延迟了 2 秒,但问题仍然存在。
    • 您需要确保在您自己的 API 调用之后发起此调用时,self 表示的屏幕对您是可见的,并且不会被任何其他 UIViewController 实例覆盖。您可以尝试在他们的示例应用程序中重现此问题 - github.com/cashfree/ios-CFWebSDK。如果它在那里,您可以提出错误/联系支持等。
    • 我都试过了,问题还是一样
    猜你喜欢
    • 1970-01-01
    • 2018-12-17
    • 1970-01-01
    • 2014-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-17
    • 2016-01-06
    相关资源
    最近更新 更多