每当我的应用程序进入前台时,我都想刷新 UIWebView。我在 ViewController.m 中真正拥有的只是一个检查 Internet 访问 (hasInternet) 和 viewDidLoad 的方法。
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize webview;
-(BOOL)hasInternet{
Reachability *reach = [Reachability reachabilityWithHostName:@"www.google.com"];
NetworkStatus internetStats = [reach currentReachabilityStatus];
if (internetStats == NotReachable) {
UIAlertView *alertOne = [[UIAlertView alloc] initWithTitle:@"You're not connected to the internet." message:@"Please connect to the internet and restart the app." delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
[alertOne show];
}
return YES;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self hasInternet];
[webView loadRequest: [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://warm-chamber-7399.herokuapp.com/"]] ];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
关于如何启用此功能的任何建议?它是进入 AppDelegate 还是我在 ViewController.m 中创建另一个方法?