9

I have a problem with the didFinishLoad method in UIWebView that is keeps firing. I want to try the estimatedProgress solution, however I dont know where to find those frameworks unfortunately. I am running Mountain Lion and using the latest version of XCode. Also, for the UIWebView firing multiple times, is this the best way to go or are there new methods. There seems to be a javascript answer on SO, however that did not work for me. That was dated back in 2009, and I hear that Apple rejects any app that uses a private API. Please help me out here!

Thanks Everybody!

2 Answers 2

2

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)

1
0

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

6
  • Basically question is to bypass all 4 loading of the web view and make the page load ready state 4 Aug 13, 2012 at 14:09
  • ready state is kind of event based thing where the webpage goes through states of loading there are 4 states as such Aug 13, 2012 at 15:20
  • @chaitanya.varanasi Alright, so that I can research this properly, what are the four ready states called? Aug 13, 2012 at 15:22
  • 0: The request is uninitialized (before you've called open()). 1: The request is set up, but not sent (before you've called send()). 2: The request was sent and is in process (you can usually get content headers from the response at this point). 3: The request is in process; often some partial data is available from the response, but the server isn't finished with its response. 4: The response is complete; you can get the server's response and use it. Aug 13, 2012 at 15:40
  • they go along the lines of loading interactive then complete Aug 13, 2012 at 15:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.