我關閉了我的網絡並運行我的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];
}
-
在此代碼區
- ,如果網絡關閉,我怎麼處理這個代碼?