您的位置:首页 > 理论基础 > 计算机网络

自己整理的IOS网络检测和版本检测代码

2013-11-09 16:29 459 查看
网络检测代码段

BOOL isExistenceNetwork;

Reachability *r = [Reachability reachabilityWithHostName:@"www.apple.com"];

switch ([r currentReachabilityStatus]) {

case NotReachable:

isExistenceNetwork=FALSE;

break;

case ReachableViaWWAN:

isExistenceNetwork=TRUE;

break;

case ReachableViaWiFi:

isExistenceNetwork=TRUE;

break;

}

if (!isExistenceNetwork) {

UIAlertView *myalert = [[UIAlertView alloc] initWithTitle:@"网络连接不佳" message:@"请检查网络连接,并重启程序" delegate:self cancelButtonTitle:@"确认" otherButtonTitles:nil,nil];

myalert.delegate = self;

myalert.tag = 2;

[myalert show];

[myalert release];

return YES;

}

版本检测代码段

if(AppVersion < version){

NSString *prompt = [NSString stringWithFormat:@"IBMUnixWorld已更新到%1.1f版本",version];

UIAlertView *av=[[[UIAlertView alloc] initWithTitle:@"版本更新" message:promptdelegate:self cancelButtonTitle:@"否" otherButtonTitles:@"是", nil] autorelease];

av.tag = 1;

[av show];

}

//alertViewDelegate

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{

//NSLog(@"clickedButtonAtIndex %d",buttonIndex);

if(alertView.tag == 1){

if(buttonIndex == 1){

NSLog(@"appStoreLinkURL %@",appStoreLinkURL);

NSString *appURL = appStoreLinkURL;

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:appURL]];

}

}else if(alertView.tag == 2){

exit(1);

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: