baker icon indicating copy to clipboard operation
baker copied to clipboard

Modal View when Offline

Open davidrsim opened this issue 14 years ago • 12 comments

First up, many thanks for the modal webview - fantastic and exactly what my application needed!

Only one glitch for me - when offline the modal window just keeps its indicator spinning and doesn't time out. Not feeding back to the user when offline is a common cause for app rejection so should probably be resolved - say through a timeout and error message if the connection fails.

davidrsim avatar Apr 16 '12 13:04 davidrsim

Good point! :) Thanks for the feedback. :)

folletto avatar Apr 16 '12 13:04 folletto

A quick fix for this - add to ModalViewController.m. It makes an additional call to the Internet and could be refined - I was going for something that didn't touch the existing code.

-(void)viewDidAppear:(BOOL)animated {
    NSString* link = @"http://google.com";
    NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:link] cachePolicy:0 timeoutInterval:5];
    NSURLResponse* response=nil;
    NSError* error=nil;
    NSData* data=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    if (data == NULL) {
        NSLog(@"Not connected");
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"Page unavailable - you don't seem to be connected to the internet right now." 
                                                       delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
        [alert release];
        [[self delegate] done:self];
    } else {
        NSLog(@"Connected");
    }
}

davidrsim avatar May 03 '12 16:05 davidrsim

Thanks @davidrsim! Unfortunately we weren't able to follow up on this, so thanks for the additional detail! :)

folletto avatar May 07 '12 21:05 folletto

Has this been added to Baker? I'm still getting a timeout. If not, does the code above still work? @davidrsim, can you explain where you added your code exactly?

tstegart avatar Jul 15 '12 17:07 tstegart

@tstegart When something gets solved or added, the topic is closed, so no we weren't able to add this yet. We were working on refactoring of the code as you can see from the other issue.

folletto avatar Jul 15 '12 17:07 folletto

Thanks. Yeah, I noticed all the work on the code the last week, it looks great! Hopefully @davidrsim can chime in with where he placed his code.

tstegart avatar Jul 15 '12 18:07 tstegart

Hi,

I added it below the loadView section, so...

    self.view.frame = CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height);
    [self.view sizeToFit];


    // ****** Attach
    [self.view addSubview:toolbar];
    [self.view addSubview:webView];
}


-(void)viewDidAppear:(BOOL)animated {
    NSString* link = @"http://google.com";
    NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:link] cachePolicy:0 timeoutInterval:5];
    NSURLResponse* response=nil;

etc... Line 154 on mine, I think!

davidrsim avatar Jul 16 '12 12:07 davidrsim

Thanks @davidrsim. I tried it, but I'm getting an error on this line:
[[self delegate] done:self]; - Instance method '-done' not found (return type defaults to "id")

tstegart avatar Jul 16 '12 14:07 tstegart

It's a warning rather than an error (you'll also see it in the (IBAction)dismissAction: section too) - it should still compile and work ok. (At least it does for me).

davidrsim avatar Jul 16 '12 15:07 davidrsim

It compiles, but throws an error when I turn off wi-fi on the iPad and try and test it.

-[RootViewController done:]: unrecognized selector sent to instance 0x1be260 2012-07-16 19:02:37.693 ONB Magazine[2260:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[RootViewController done:]: unrecognized selector sent to instance 0x1be260' *** First throw call stack: (0x3603488f 0x37289259 0x36037a9b 0x36036915 0x35f91650 0x23cd9 0x30cebd3d 0x30d45f2d 0x30d74de7 0x30da5761 0x30d43d77 0x30d43bfb 0x30cbec53 0x30cc457d 0x37da5c2f 0x36e2ce91 0x360072ad 0x35f8a4a5 0x35f8a36d 0x3234a439 0x30cd7e7d 0x228f 0x2240) terminate called throwing an exception(lldb)

tstegart avatar Jul 17 '12 00:07 tstegart

I could't get the code above to work for me, so I snooped on the internet and found this link: http://stackoverflow.com/questions/9094830/testing-internet-connection-on-ipad-app-using-ios5

I added the example code to ModalViewController.m around line 188 just after webViewDidStartLoad. I then added in@davidrsim's warning code and tweaked the message a little. It seems to work just fine, although it could be improved. After you click on "OK," you're still stuck in modal view with a blank page and the spinner is still spinning. Adding another button to the warning to "Go Back" might be useful to take people back to the book page they were viewing before they opened modal view. Maybe this can be added to the next version of Baker.

Code below:

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
    if (![[error domain] isEqualToString:NSURLErrorDomain]) {
        return;
    }

    // Show warning to user that device is not connected
    NSLog(@"Not connected");
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"The page you are trying to reach is unavailable - you don't seem to be connected to the internet right now." 
                                                   delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
    [alert release]; 
}

tstegart avatar Jul 19 '12 17:07 tstegart

We have added a error message on the modal window with the commit 8bdffd7ccec440f52535fdc189b0b548dbb35ac2. The error appears when a user tries to load a page without internet connection.

Xm4s avatar Sep 27 '12 21:09 Xm4s