iPhone uygulamamdaki HTTP Durum Kodlarını kontrol edip değerlendirmem gerekiyor.HTTPResponse/HTTPRequest durum kodlarını al iPhone SDK?
// create the request
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.apple.com/"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
// create the connection with the request
// and start loading the data
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConnection) {
// Create the NSMutableData that will hold
// the received data
// receivedData is declared as a method instance elsewhere
receivedData=[[NSMutableData data] retain];
} else {
// inform the user that the download could not be made
}
Burada bu kodu var: Ben başarıyla (Sanırım) siteye bağlanmak bir NSURLRequest nesnesi ve bir NSURLConnection var http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/URLLoadingSystem/Tasks/UsingNSURLConnection.html
Ama (bildiğim kadarıyla olabildiğince değil HTTP Durum kodlarına erişme hakkında bir şey söyleyin.
Bir siteye nasıl bağlantı kuracağına dair herhangi bir fikrin var mı ve daha sonra bu bağlantının HTTP Durum Kodlarını kontrol edin.
Şimdiden teşekkürler!
#pragma mark -
#pragma mark NSURLConnection Delegate Methods
- (void)connection:(NSURLConnection*)connection didReceiveResponse:(NSURLResponse*)response {
NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response;
int responseStatusCode = [httpResponse statusCode];
}
Ama uyumsuz bir NSURLConnection kullanıyorum, bu nedenle bu size yardımcı olabilir:
Bu, ihtiyacım olan şeyi başardı. Tek sorun, URL/IP Addy yoksa, hiçbir yanıt alınmaz, bu yüzden uygulama sadece orada sonsuza kadar askıda kalıyor. Şu anda bu sorunu çözmek için bir yol arıyorum ... herhangi bir öneri takdir edilecektir ... – cmcculloh
Apple Reachabilty kodu bak. Yalnızca bildirim yöntemini kullanın (varsayılan olarak kodda etkin değil, init yöntemindeki yorumları görün) ve her zaman kontrol etmek istediğiniz ana bilgisayarı ayarlayın. http://stackoverflow.com/questions/477852/checking-for-internet-connectivity-in-objective-c –