在谷歌上搜索了几个小时后,我仍然找不到关于这个主题的一个主题:
如果用户没有internet connection.
我该把这些放在哪里呢?我尝试了一个主题,但它没有显示警报视图消息。
下面是我的代码:
- (IBAction)getDataPressed
{
if([myRequest_ isExecuting])
{
return;
}
if(myRequest_ != nil)
{
[myRequest_ release];
}
myRequest_ = [[ASIHTTPRequest alloc]initWithURL:[NSURL URLWithString:URL_PATH]];
myRequest_.delegate = self;
[myRequest_ startAsynchronous];
}
#pragma ASI Delegate methods
- (void)requestFinished:(ASIHTTPRequest *)request
{
NSLog(@"Request finished successfully");
NSLog(@"%@",[request responseString]);
NSDictionary *responseDictionary = [[request responseString]JSONValue];
NSDictionary *arrayElement = [responseDictionary objectForKey:@"user"];
NSString *ID = [arrayElement valueForKeyPath:@"id"];
NSLog(@"id: %@",ID);
NSString *usr = [arrayElement valueForKeyPath:@"usr"];
NSLog(@"usr: %@",usr);
NSString *gd = [arrayElement valueForKeyPath:@"gd"];
NSLog(@"gd: %@",gd);
NSString *ag = [arrayElement valueForKeyPath:@"ag"];
NSLog(@"ag: %@",ag);
NSString *st = [arrayElement valueForKeyPath:@"st"];
NSLog(@"st: %@",st);
NSString *lf = [arrayElement valueForKeyPath:@"lf"];
NSLog(@"lf: %@",lf);
NSString *da = [arrayElement valueForKeyPath:@"da"];
NSLog(@"da: %d",da);
for(NSString *value in [arrayElement allValues]){
NSLog(@"Found Value %@",value);
label.text = [value stringByAppendingFormat:@",%@,%@,%@,%@,%@,%@,",ID,usr,gd,ag,st,lf];
}
}
- (void)requestFailed:(ASIHTTPRequest *)request
{
NSLog(@"Error %@", [request error]);
if([request error])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Destination Unreachable" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
-(void) dealloc
{
[super dealloc];
}感谢那些将帮助^_^的人
发布于 2011-12-07 18:16:44
我想你可以试试Reachbility应用程序来帮你检查你有没有上网。至于服务器本身,您可以使用NSUrlConnection Delegate方法来检查您的请求是否存在问题(通过查看附带的HTTP代码)
https://stackoverflow.com/questions/8412835
复制相似问题