【发布时间】:2011-06-04 10:57:47
【问题描述】:
我是网络服务的新手。我需要从 .NET Web 服务器获取信息。为此,我使用以下代码:
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[webData setLength: 0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[webData appendData:data];
if (data) {
NSLog(@" bcxbm,xcm,xcmcmx,b data consist %@",data);
}
else {
NSLog(@"not exist");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"UIAlertView" message:@"<Alert message>" delegate:self cancelButtonTitle:@"Retry" otherButtonTitles:@"Cancel", nil];
[alert show];
[alert release];
}
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSLog(@"ERROR with theConenction");
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"DONE. Received Bytes: %d", [webData length]);
我能够获取信息,但我需要对其进行验证。如果没有连接,我需要触发Alertview。为此,我有代码:
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[webData appendData:data];
if (data) {
NSLog(@" bcxbm,xcm,xcmcmx,b data consist %@",data);
}
else {
NSLog(@"not exist");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"UIAlertView" message:@"<Alert message>" delegate:self cancelButtonTitle:@"Retry" otherButtonTitles:@"Cancel", nil];
[alert show];
[alert release];
}
}
我通过删除连接来检查。但它不会触发任何警报。一段时间后,它会在控制台中显示Error in connection。但这需要很多时间。除了这个还有其他可能吗?没有连接时如何显示警报?
谁能帮帮我?
【问题讨论】:
标签: iphone