How can I get the data from the url on the iPhone?

I am using code from an Apple Document to execute some HTTP messages. I can connect to the URL successfully, but I could not get the data from my server.

// 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
}

The reason may be:

  • I declare receivedDatain the action itself. The annotation says that I have to state this elsewhere. Where should I announce this? Should I declare it as a property of the controller?

  • How to [[NSMutableData data] retain]find the url as it is outside if{}?

+3
source share
1 answer

NSURLConnection initWithRequest: delegate: method, ( ) . , , , .

, , NSURLConnection. , -: didReceiveData: delegate. , , NSData, . NSMutableData , . , , -connectionDidFinishLoading: .

:

  • , . NSURLConnection initWithRequest: delegate:, , . -connection: didReceiveResponse: , HTTP .

  • URL-, , , , .

+5

Source: https://habr.com/ru/post/1703937/


All Articles