Ich benutze Apple Document, um eine App zu erstellen. Ich bin erfolgreich in Verbindung mit dem Server, aber ich erhalte 0 Bytes vom Server (keine Antwortdaten). Ich nehme die folgenden Schritte:Empfangen von Daten von der URL auf dem iPhone?
ich eine Ansicht-basierte App erstellen und fügen Sie eine Eigenschaft 'receivedData':
In ViewController.h:
@property (nonatomic, retain) NSMutableData *receivedData;
In ViewController.m:
@synthesize receivedData;
ViewController.m der Aktion 'ViewDidLoad', füge ich:
receivedData = [NSMutableData alloc];
eine Schaltfläche in der Ansicht und für sie Aktion hinzufügen:
// 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 receivedData=[[NSMutableData data] retain]; } else { // inform the user that the download could not be made }
Wenn ich diese Codes debuggen, finde ich, dass receivedData 0 Byte zurückgibt. Irgendwelche Ideen über was schief geht? Eine einfache Änderung meines Codes wird geschätzt.
Vielen Dank. Die Methode mit 'didReceiveData' wurde hinzugefügt und ich erhalte erfolgreich die Daten vom Server. –