我关闭了我的网络并运行我的ios程序。 然后停留程序。使用NSURLConnection连接失败,如何重新连接?
当我打开我的网络后。我的程序仍然停止。
我想在ios中重新连接NSURLConnection。
-(void) applistDBdownload
{
NSString *file = [NSString stringWithFormat:@"http://sok129.cafxxx.com/oneapplist.sqlite3"];
NSURL *fileURL = [NSURL URLWithString:file];
NSURLRequest *req = [NSURLRequest requestWithURL:fileURL];
connect= [NSURLConnection connectionWithRequest:req delegate:self];
fileData = [[NSMutableData alloc] initWithLength:0];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSLog(@"fail"); -> come in when network off.
-> no come in when network on
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
-> no come in when network on
-> come in when network off
}
1.如何重新连接?
和
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
if(self.connect!=connection)
{
NSLog(@"noconnect");
return;
}
[self.fileData appendData:data];
}
-
在此代码区
- ,如果网络关闭,我怎么处理这个代码?