baker
baker copied to clipboard
Checking internet before download the book.
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.
We'll look into this - or alternative ways to solve the same issue.
For reference, here's how to reproduce the issue:
- Open shelf
- Turn off connection
- Download a book: loader is stuck on "connecting..." indefinitely
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.