帮助newby!我的应用程序有3个视图控制器。 VC#3(*赞助商)将用户带到我的网站&所以我正在尝试为这个VC实现Reachability。我添加了系统配置框架&苹果可达性.H& .M文件到项目。已禁用ARC for Reachability .M文件& VC#3 .M文件。项目B& R很好,但是当我断开网络连接时,我仍然没有得到弹出警报。我还将Reachability.h导入VC#3。我错过了什么?请帮忙。
VC#3(*赞助商).M
`
#import "Sponsor.h"
#import "ViewController.h"
@interface Sponsor ()
@end
@implementation Sponsor
-(void)viewDidLoad {
[webview loadRequest:[NSURLRequest requestWithURL:[NSURL
URLWithString:@"http://opticertificationprep.webs.com/"]]];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
-(IBAction)home:(id)sender{
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (BOOL) hasInternet {
Reachability *reach = [Reachability
reachabilityWithHostName:@"www.opticertificationprep.webs.com"];
NetworkStatus internetStats = [reach currentReachabilityStatus];
if (internetStats == NotReachable) {
UIAlertView *alertOne = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Check Your Internet Connection" delegate:self cancelButtonTitle:@"Okay"
otherButtonTitles:nil];
[alertOne show];
[alertOne release];
}
return YES;
}
`
答案 0 :(得分:0)
对于有同样问题的人。我在.M文件中遗漏了这段代码。一旦我添加它,我的弹出警报就会很好。
`
-(void)viewDidLoad {
{
[super viewDidLoad];
[self hasInternet];
}
`