Here are my files. When I click the reload button it goes into what I understand is a segfault in OBJC. I don't think it is the website but something in the main that is not being met/returned. It gives the SIGABRT in the main.m file. I've tried to enable zombies to no avail and if that is the way to go please let me know.
//
// main.m
// webKitExp
//
// Created by J.Doe on 8/14/17.
// Copyright © 2017 J.Doe. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char * argv[]) {
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
//
// ViewController.h
// webKitExp
//
// Created by J.Doe
// Copyright © 2017 J.Doe. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <WebKit/WebKit.h>
@interface ViewController : UIViewController
@property (nonatomic, retain) IBOutlet UIWebView *webView;
@end
//
// ViewController.m
// webKitExp
//
// Created by J.Doe on 8/14/17.
// Copyright © 2017 J.Doe. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize webView;
- (void)viewDidLoad {
[super viewDidLoad];
[UIView setAnimationsEnabled:NO];
NSString *localURL = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:localURL]];
[webView loadRequest:urlRequest];
}
- (IBAction)buttonClicked:(UIButton *)sender {
[webView reload];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
Since ios8+ you should use WKWebview instead of UIWebview. @Henly ans is in Swift3 ,here is the Objective-C version of the same.
- (void)viewDidLoad {
[super viewDidLoad];
_wkWebview = [[WKWebView alloc] initWithFrame:self.view.frame];
_wkWebview.navigationDelegate = self ;
[self.view addSubview:_wkWebview ];
NSURL *url = [NSURL URLWithString:@"https://www.google.com"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[_wkWebview loadRequest:request];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button addTarget:self action:@selector(reload) forControlEvents:UIControlEventTouchUpInside];
[button setTitle:@"Reload" forState:UIControlStateNormal];
button.frame = CGRectMake(50.0, 200.0, 50.0, 50.0);
[self.view addSubview:button];
}
-(void)reload{
[self.wkWebview reload];
}
Do not forget to import WebKit to make it working #import <WebKit/WebKit.h>
Do let me know if you any queries in comment. I will try and help.