-1

I use Ionic capacitor for my ios application; I need to get access to WKWebView configuration and set background color. How access it from AppDelegate file in ios?

I can do it through capacitor plugin with these lines of code, but i want to find better solution:

    override public func load() {
        let webView = self.bridge?.webView
        webView?.backgroundColor = UIColor.black;
    }

Nigidoz
  • 360
  • 2
  • 6

1 Answers1

0

Ionic Capacitor use CAPBridgeViewController as root viewController;

Before actual setting property for WKWebView, we have to be sure, that view already loaded to not get situation, where our properties overwritten or not exists at all; And then, we can set actual value of backgroundColor that we need;

Code could look like that:

    func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
        (window?.rootViewController as? CAPBridgeViewController)?.loadViewIfNeeded();
        (window?.rootViewController as? CAPBridgeViewController)?.webView?.backgroundColor = UIColor.black;
        return true
    }
Nigidoz
  • 360
  • 2
  • 6