Listen to the URL navigation event

From IAPConnect 2.1.26, Griver supports custom navigation events. By Implementing the GRVURLNavigationEventDelegate protocol, You can decide how to navigate to a URL page. Here are the detailed steps:

Step 1. Implement GRVURLNavigationEventDelegate

You should implement the GRVURLNavigationEventDelegate protocol, and implement the methods according to your needs:

  1. Configure URL list to be opened by UIApplication open method.
  2. Configure URL list to be opened by WebView loadRequest method.
  3. Implement custom navigation action.
  4. Implement custom method to allow the URL to be loaded without permission checks.

Note: You should configure the URL by regular expression syntax.

For example:

copy
class DemoURLNavigationEventDelegate: NSObject,GRVURLNavigationEventDelegate {
    
    // Configure URL list to be opened by UIApplication open method.
    func urlListOpenByApplication() -> [String]! {
        return ["^https://www[.]taobao[.]com[^\\s]*"]
    }
    
    // Configure URL list to be opened by WebView loadRequest method.
    func urlListOpenByContainer() -> [String]! {
        return ["^http(s)?://www[.]lazada[.]com[.]ph[^\\s]*"]
    }
    
    //Implement custom navigation action.
    func willStartURLNavigation(_ context: GRVNavigationContext!) -> Bool {
        if context.url.absoluteString.hasPrefix("https://www.google.com") {
            print("App manage it!")
            return true
        }
        return false
    }

    // Implement custom method to allow the URL to be loaded without permission checks.
    func allowLoadURLWithoutPermissionCheck(_ url: URL) -> Bool {
        if url.host.hasPrefix("google.com") {
            return true
        }
        
        return false
    }
}

Step 2. Configure GRVExtensionDelegate for urlNavigationEventDelegate

You should configure your Navigation Event Delegate class to extensionDelegate.urlNavigationEventDelegate. For example:

copy
let extensionDelegate = GRVExtensionDelegate()
extensionDelegate.urlNavigationEventDelegate = DemoURLNavigationEventDelegate()