baker icon indicating copy to clipboard operation
baker copied to clipboard

Checking internet before download the book.

Open aspek opened this issue 13 years ago • 2 comments

I have an idea for check internet if user go offline.

IssueViewController.m

find / - (void)download / And add conditions like this.

- (void)download
{
    if([self connectedToInternet] == NO)
    {
        NSLog(@"No internet");
        UIAlertView* alert= [[UIAlertView alloc]initWithTitle:@"Warning" message:@"No Internet Connection or Server maintenance" delegate:nil cancelButtonTitle:@"Continue" otherButtonTitles:nil, nil];
        [alert show];
        [alert release];

    }
    else
    {

        [self refresh:@"connecting"];
        [self.issue download];
    }


}

// add Bool for checking internet
- (BOOL)connectedToInternet
{
    NSString *urlString = @"http://yourdomain/";
    NSURL *getURL = [NSURL URLWithString:urlString];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:getURL];
    [request setHTTPMethod:@"HEAD"];
    NSHTTPURLResponse *response;

    [NSURLConnection sendSynchronousRequest:request returningResponse:&response error: NULL];

    return ([response statusCode] == 200) ? YES : NO;
}

Now test press download button. Don't forget turn off the wifi.

aspek avatar Feb 17 '13 18:02 aspek

We'll look into this - or alternative ways to solve the same issue.

For reference, here's how to reproduce the issue:

  1. Open shelf
  2. Turn off connection
  3. Download a book: loader is stuck on "connecting..." indefinitely

Simbul avatar Mar 11 '13 22:03 Simbul

We ended up using an existing library (https://github.com/tonymillion/Reachability) but your code is essentially doing the same thing. Thanks for pointing out the issue.

Simbul avatar Mar 11 '13 23:03 Simbul