How to find last load of UIWebView(Ready State 4)

天大地大妈咪最大 提交于 2019-12-05 02:12:44

What about keeping track of the number of outstanding requests? I whipped up some test code that seems to work:

@interface WebViewDelegate : NSObject<UIWebViewDelegate>
@property ( nonatomic ) NSUInteger numberOfRunningRequests ;
@end

@implementation WebViewDelegate

-(void)webViewDidStartLoad:(UIWebView *)webView
{
    self.numberOfRunningRequests = self.numberOfRunningRequests + 1 ;
}

-(void)webViewDidFinishLoad:(UIWebView *)webView
{
    self.numberOfRunningRequests = self.numberOfRunningRequests - 1 ;
    if ( self.numberOfRunningRequests == 0 )
    {
        NSLog(@"done!\n") ;
    }
}

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];

    UIWebView * webView = [[ UIWebView alloc ] initWithFrame:self.window.bounds ] ;
    static WebViewDelegate * delegate = nil ;
    delegate = [[ WebViewDelegate alloc ] init ] ;
    webView.delegate = delegate ;

    [self.window addSubview:webView ] ;
    NSURLRequest * request = [ NSURLRequest requestWithURL:[ NSURL URLWithString:@"http://stackoverflow.com"] ];
    [ webView loadRequest:request ] ;
    return YES;
}

@end

(Create an Xcode sample project and replace your AppDelegate.m with this)

Mick MacCallum

If by frameworks you mean the .h files imported in the code on the page you linked to, here's the link to directly download them. For further help you'll need to elaborate more.

EDIT: Additionally, please see: NSURLConnection NSURLRequest proxy for asynchronous web service calls

The linked answer explains how to NSURLRequest to request a connection and get different callbacks for different states of the request, such as - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!