Skip to content

Instantly share code, notes, and snippets.

@bolencki13
Created March 26, 2017 16:28
Show Gist options
  • Save bolencki13/5784511b0d9b3e69f72388cfe0283b00 to your computer and use it in GitHub Desktop.
Save bolencki13/5784511b0d9b3e69f72388cfe0283b00 to your computer and use it in GitHub Desktop.
WKWebView load request with completion block
//
// WKWebview+Complete.h
// partyface
//
// Created by Brian Olencki on 3/26/17.
// Copyright © 2017 Brian Olencki. All rights reserved.
//
#import <WebKit/WebKit.h>
@interface WKWebView (Complete)
- (WKNavigation *)loadRequest:(NSURLRequest *)request complete:(void(^)())complete;
@end
//
// WKWebview+Complete.m
// partyface
//
// Created by Brian Olencki on 3/26/17.
// Copyright © 2017 Brian Olencki. All rights reserved.
//
#import "WKWebView+Complete.h"
@implementation WKWebView (Complete)
- (WKNavigation *)loadRequest:(NSURLRequest *)request complete:(void (^)())complete {
WKNavigation *navigation = [self loadRequest:request];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
while (self.isLoading) {
[NSThread sleepForTimeInterval:0];
}
dispatch_async(dispatch_get_main_queue(), ^(void){
complete();
});
});
return navigation;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment