Listen for the URL navigation event
This topic guides you on how to listen for the URL navigation event.
From IAPConnect 2.1.26, Griver
supports customized URL navigation events. By Implementing the GRVURLNavigationEventDelegate
protocol, You can decide how to navigate to a URL page.
Procedures
Implement the GRVURLNavigationEventDelegate
protocol
Implement the GRVURLNavigationEventDelegate protocol and write code in the required methods according to your business logic.
Note: Configure the URL by the regular expression syntax.
Code sample:
class DemoURLNavigationEventDelegate: NSObject,GRVURLNavigationEventDelegate {
func urlListOpenByContainer() -> [String] {
// return the URL list that needs to open by SDK container
}
func urlListOpenByApplication() -> [String] {
// return the URL list that needs to open by UIApplication
}
func willStartURLNavigation(_ context: GRVNavigationContext) -> Bool {
// URL navigation intercept
}
func allowLoadURLWithoutPermissionCheck(_ url: URL?) -> Bool {
// URL: wheher skip the permission check
}
}
Register the GRVURLNavigationEventDelegate
protocol
Refer to the following code sample. Configure the GRVExtensionDelegate
to register the URL navigation event (GRVURLNavigationEventDelegate
) after initializing the SDK.
let extensionDelegate = GRVExtensionDelegate()
extensionDelegate.urlNavigationEventDelegate = DemoURLNavigationEventDelegate()
Protocol
GRVURLNavigationEventDelegate
protocol
Code sample:
@protocol GRVURLNavigationEventDelegate <NSObject>
@optional
// URL list should be opened by Griver Container
- (NSArray<NSString *> * _Nonnull)URLListOpenByContainer;
// URL list should be opened by Application
- (NSArray<NSString *> * _Nonnull)URLListOpenByApplication;
/**
Will start URL Navigation.
@param context GRVNavigationContext
@return YES - handle URL Navigation in this method ; NO - Container will handle URL navigation event by default
*/
- (BOOL)willStartURLNavigation:(GRVNavigationContext * _Nonnull)context;
/// This method is called just before the permission check for url loading.
/// You may return YES to allow the url loading without permission check.
/// @param url the url being loaded
/// @return YES - allow the url loading without permission check; NO - do permission check
- (BOOL)allowLoadURLWithoutPermissionCheck:(NSURL * _Nullable)url;
@end
Methods
URLListOpenByContainer
Return value
Field name | Data type | Required | Description |
N/A | NSArray<NSString *> | Yes | Returnt the URL list that is opened by Griver Container. |
URLListOpenByApplication
Return value
Field | Data type | Required | Description |
N/A | NSArray<NSString *> | Yes | Returnt the URL list that is opened by Application. |
willStartURLNavigation:
Parameters
Field | Data type | Required | Description |
context | Yes | The context of the page navigation. |
GRVNavigationContext
Field | Data type | Required | Description |
currentViewController | UIViewController | No | The current view controller associated with the navigation context. |
webView | WKWebView | No | The |
URL | NSURL | No | The URL that is currently being loaded or operated on. |
Code sample:
/**
* @brief Context object for managing navigation state in a web view.
*
* This class holds references to the current view controller, web view instance, and URL during navigation operations.
*/
@interface GRVNavigationContext : NSObject
/// The current view controller associated with the navigation context (can be nil).
@property(nonatomic, strong, nullable) UIViewController *currentViewController;
/// The WKWebView instance used for web content rendering (can be nil).
@property(nonatomic, strong, nullable) WKWebView *webView;
/// The URL currently being loaded or operated on (can be nil).
@property(nonatomic, strong, nullable) NSURL *URL;
@end
Return value
Field | Data type | Required | Description |
N/A | BOOL | Yes |
|
allowLoadURLWithoutPermissionCheck:
Parameters
Field | Data type | Required | Description |
url | NSURL | No | The URL that is being loaded. |
Return value
Field | Data type | Required | Description |
N/A | BOOL | Yes |
|