After placing a Webkit View in Storyboard and dragging Outlet to the code use the following code:
Viewcontroller. h
#import <UIKit/UIKit.h>
#import <WebKit/WebKit.h>
@interface ViewController : UIViewController <WKNavigationDelegate>
@property (weak, nonatomic) IBOutlet WKWebView *webView;
@end
Viewcontroller. m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.webView.navigationDelegate = self;
//URL do site que deseja iniciar webView
NSString * mURL = @"https://www.google.com";
NSString * webStringURL = [mURL stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]];
NSURL* url = [NSURL URLWithString:webStringURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[_webView loadRequest: requestObj];
}
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
if(navigationAction.navigationType == WKNavigationTypeLinkActivated) {
// Aqui você recebe a URL atual
NSLog(@"%@", navigationAction.request.URL);
}
decisionHandler(WKNavigationActionPolicyAllow);
}
@end
Thank you for the reply
– Leandro Santos