我关闭网络并运行我的 ios 程序。然后保持停止程序。
当我打开我的网络之后。我的程序仍然停止。
我想在 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];
}
- 在这个代码区域,如果网络关闭,我如何处理这个代码?