¿Cómo puedo recibir datos de la URL en el iPhone?
Estoy usando el código del documento de Apple para hacer alguna comunicación HTTP. Puedo conectarme a la URL con éxito, pero no pude recibir los datos de mi servidor.
// create the request
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://..."]
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
NSMutableData *receivedData=[[NSMutableData data] retain];
} else {
// inform the user that the download could not be made
}
La razón puede ser:
DeclaroreceivedData
en la acción misma. La anotación dice que debería declararlo en otro lugar. ¿Dónde debo declararlo? ¿Debo declararlo como propiedad del controlador?
¿Cómo puede[[NSMutableData data] retain]
encuentre la URL ya que está fuera de laif{}
?