Jesse Durham
Jesse Durham

Reputation: 285

NSURLconnection fails on 3g 'network connection was lost'

I have an app that uses NSURLconnection that seems to consistently fail to communicate to a web service when using 3G with the error 'the network connection was lost.' However, the app runs just fine with wifi.

Any ideas as to what could possibly be the problem? Do I need to do anything special with NSURLconnection to handle 3G?

one NSURL code example I use.

        NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:req delegate:self];
    if (conn) {
        XMLData = [NSMutableData data];     
    }

delegate methods

 -(void) connection:(NSURLConnection *) connection 
 didReceiveResponse:(NSURLResponse *) response {
    [XMLData setLength: 0];
 }

-(void) connection:(NSURLConnection *) connection 
didReceiveData:(NSData *) receiveddata {
[XMLData appendData:receiveddata];
}

-(void) connection:(NSURLConnection *) connection 
   didFailWithError:(NSError *) error {
     self.errorLabel.text = [error localizedDescription];

 }

 -(void) connectionDidFinishLoading:(NSURLConnection *) connection {
     NSLog(@"DONE. Received Bytes: %d", [XMLData length]);
     NSString *theXML = [[NSString alloc] 
                    initWithBytes: [XMLData mutableBytes] 
                    length:[XMLData length] 
                    encoding:NSUTF8StringEncoding];

   //i do some xml parsing on the data returned
   }

Upvotes: 0

Views: 1186

Answers (1)

self
self

Reputation: 1215

I would start putting NSLog's in the delegate methods. Start with didReceiveData.

 -(void) connection:(NSURLConnection *) connection didReceiveData:(NSData *) receiveddata          { 
            if (receiveddata != nil){ 
            [XMLData appendData:receiveddata];
             NSLog(@"didReceiveData :receiveddata is:%@", receiveddata);

            }
    else{ 
        NSLog(@"NO Data:%@");
        }

    }

Upvotes: 1

Related Questions