Я недавно перешел с UIWebView на WKWebView в XCode, и пока все в порядке. Но когда я использую поле галочки «Предварительный просмотр ссылки» (эта функция очень полезна для меня) в Инспекторе атрибутов IB, приложение возвращается полностью черным, когда оно было в фоновом режиме. Это означает, что пользователь должен убить его, когда он захочет использовать его снова.
Вот код для WebViewController:
@interface WebViewController ()
@end
@implementation WebViewController
@synthesize activityIndicatorView = _activityIndicatorView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
NSLog(@"Webview");
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
_webView.UIDelegate = self;
_webView.navigationDelegate = self;
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.webLink]]];
[self setupConstraints];
}
-(void)setupConstraints {
[self.webView setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.webView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view.safeAreaLayoutGuide attribute:NSLayoutAttributeTop multiplier:1.0 constant:0.0]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.webView attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeading multiplier:1.0 constant:0.0]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.webView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeWidth multiplier:1.0 constant:0.0]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.webView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.view.safeAreaLayoutGuide attribute:NSLayoutAttributeHeight multiplier:1.0 constant:0.0]];
}
@end
и вот как я вызываю WKWebViewController из a tableView:
WebViewController *webVC = [[WebViewController alloc] initWithNibName:@"WebViewController" bundle:nil];
webVC.webLink = str;
[self.navigationController pushViewController:webVC animated:YES];
как я могу предотвратить контроллер, чтобы быть черным, когда «Предварительный просмотр ссылки» включен, и приложение возвращается после того, как оно было в фоновом режиме?
(Xcode 11.4. 1, цель iOS 11)
Большое спасибо! Martin