üzerinde HTTP istisnası işleme ile ilgili soru İstisnaı işlemek için bir yöntem eklemek çalışıyorum, ancak program bir AlertView açılır yerine çöküyor.IPhone
-(void)connect:(NSString *)strURL
{
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:strURL]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConnection)
{
// receivedData is declared as a method instance elsewhere
receivedData = [[NSMutableData data] retain];
}
else
{
// inform the user that the download could not be made
}
}
2) ben eklemek yöntem veri almak ve dizeye conver:
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
// append the new data to the receivedData
// receivedData is declared as a method instance elsewhere
[receivedData appendData:data];
ReturnStr = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
}
3) Ben istisna kolu yöntemi ekleyin:
1) Ben bağlantı kurmak
-(void) connection:(NSURLConnection *)connection didFailWithError: (NSError *)error {
UIAlertView *errorAlert = [[UIAlertView alloc]
initWithTitle: [error localizedDescription]
message: [error localizedFailureReason]
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[errorAlert show];
}
StrURL'yi yanlış bir URL'ye değiştirdikten sonra, program çöküyor. AlertView'ın neden açılmadığına dair herhangi bir fikir var mı?
ile hata ayıklayıcı program sayesinde çalışan denediniz mi? 'didFailWithError'ınız aranıyor mu? Hata nedir? –
Hayır, 'didFailWithError' yöntemi çağrılmadı. Bağlanmak için yanlış bir URL kullanıyorum, bu yüzden neden çağrılmadığını anlamıyorum. –