1

I build sample app that load youtube in webview, sometimes in specific videos the app is crash. This is the log:

This application is modifying the autolayout engine from a background thread, which can lead to engine corruption and weird crashes. This will cause an exception in a future release.

I know that this is main thread issue when player start play the video, but not have solution, another thing that maybe can help to solve this, when this is happened, the webview delegate methud -shouldStartLoadWithRequest not called...

This is my viewWillApear :

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    _ytWebView.delegate = self;
    _ytWebView.allowsLinkPreview = YES; 
    NSURL *url = [NSURL URLWithString:@"https://www.youtube.com"];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];

    [_ytWebView loadRequest:request];

}

Any help would be appreciated.

Meet Doshi
  • 4,241
  • 10
  • 40
  • 81
Yakir Sayada
  • 171
  • 1
  • 11
  • Helper library for iOS developers looking to add YouTube video playback in their applications via the iframe player in a UIWebView https://github.com/youtube/youtube-ios-player-helper – rafaperez Jun 30 '16 at 22:26

1 Answers1

0

Try running it on the main thread instead:

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    _ytWebView.delegate = self;
    _ytWebView.allowsLinkPreview = YES; 
    NSURL *url = [NSURL URLWithString:@"https://www.youtube.com"];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
dispatch_async(dispatch_get_main_queue(), ^{
    [_ytWebView loadRequest:request];
});
}
Mtoklitz113
  • 3,828
  • 3
  • 21
  • 40