title: unable to use nsurlconnection in another method ios
body: <p>I have used the NSURLConnection in the below way in my app. But when I am trying to do the same in another method of the same class, the connection does not get established. I am not getting any error. When debugged, I saw that the program does not go into the below code. Please help.</p>
  
  <p>EDIT:</p>
  
  <pre><code>if ([self hasInternetConnection] || [self hasWiFi] || [self canReachHost:@"http://myservice.asmx"]) {
          NSLog(@"Refreshing...");
  
          NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
          NSString *defaultPhoneNumber = [defaults objectForKey:@"PhoneNumber"];
  
          NSString *xmlString = [NSString stringWithFormat:@"&lt;ServiceCalls&gt;&lt;ServiceCall&gt;&lt;Phone_No&gt;%@&lt;/Phone_No&gt;&lt;/ServiceCall&gt;&lt;/ServiceCalls&gt;", defaultPhoneNumber];
          xmlString = [xmlString stringByReplacingOccurrencesOfString:@"&lt;" withString:@"&amp;lt;"];
          xmlString = [xmlString stringByReplacingOccurrencesOfString:@"&gt;" withString:@"&amp;gt;"];
  
          NSLog(@"%@", xmlString);
  
          //NSString *xmlString = @"&amp;lt;?xml version=\"1.0\"?&amp;gt;&amp;lt;ServiceCalls&amp;gt;&amp;lt;ServiceCall&amp;gt;&amp;lt;Phone_No&amp;gt;03102497593&amp;lt;/Phone_No&amp;gt;&amp;lt;/ServiceCall&amp;gt;&amp;lt;/ServiceCalls&amp;gt;";
  
          NSString *soapMessage = [NSString stringWithFormat:
                                   @"&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n"
                                   "&lt;soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"&gt;\n"
                                   "&lt;soap:Body&gt;\n"
                                   "&lt;GetVehiclesByPhone_ServiceCall_Proc xmlns=\"http://tempuri.org/\"&gt;\n"
                                   "&lt;xmlStr&gt;%@&lt;/xmlStr&gt;\n"
                                   "&lt;m_LoginId&gt;%@&lt;/m_LoginId&gt;\n"
                                   "&lt;m_pass&gt;%@&lt;/m_pass&gt;\n"
                                   "&lt;/GetVehiclesByPhone_ServiceCall_Proc&gt;\n"
                                   "&lt;/soap:Body&gt;\n"
                                   "&lt;/soap:Envelope&gt;\n", xmlString, @"User", @"pass"];
  
          NSLog(@"soapMessage: \n%@",soapMessage);
  
          NSURL *url = [NSURL URLWithString:@"http://myservice.asmx"];
          NSMutableURLRequest *request1 = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60.0f];
          NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
  
          [request1 addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
          [request1 addValue:@"http://tempuri.org/GetVehiclesByPhone_ServiceCall_Proc" forHTTPHeaderField:@"SOAPAction"];
          [request1 addValue:msgLength forHTTPHeaderField:@"Content-Length"];
          [request1 setHTTPMethod:@"POST"];
          [request1 setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES]];
  
          NSLog(@"%@", request1);
  
          NSOperationQueue *queue = [[NSOperationQueue alloc] init];
          [NSURLConnection sendAsynchronousRequest:request1 queue:queue completionHandler:^(NSURLResponse *response, NSData *data1, NSError *error) {
  
              if (data1 != nil) {
                  if ([data1 length] &gt; 0 &amp;&amp; error == nil) {
                      NSString *theXML = [[NSString alloc] initWithBytes:[data1 bytes] length:[data1 length] encoding:NSUTF8StringEncoding];
                      theXML = [theXML stringByReplacingOccurrencesOfString:@"&amp;lt;" withString:@"&lt;"];
                      theXML = [theXML stringByReplacingOccurrencesOfString:@"&amp;gt;" withString:@"&gt;"];
                      NSLog(@"THE XML= %@",theXML);
                      NSData *receivedData = [theXML dataUsingEncoding:NSUTF8StringEncoding];
  
                      NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:receivedData];
                      xmlParser.delegate = (id)self;
                      [xmlParser parse];
  
                      NSString *delete = [NSString stringWithFormat:@"DELETE FROM Vehicles"];
  
                      char *err;
  
                      if (sqlite3_exec(db, [delete UTF8String], NULL, NULL, &amp;err) == SQLITE_OK) {
                          for (NSObject *currentObject in entries) {
                              NSLog(@"Entries: %@", [currentObject valueForKey:@"vrn"]);
                              NSString *insert = [NSString stringWithFormat:@"INSERT INTO Vehicles VALUES ('%@', '%@', '%@' , '%@')", [currentObject valueForKey:@"vrn"], [currentObject valueForKey:@"make"], [currentObject valueForKey:@"model"], [currentObject valueForKey:@"yearMade"]];
                              if (sqlite3_exec(db, [insert UTF8String], NULL, NULL, &amp;err) != SQLITE_OK) {
                                  sqlite3_close(db);
                                  NSAssert(0, @"Could not update table");
                                  [defaults setInteger:0 forKey:@"DataExists"];
                              }
                              else {
                                  [defaults setInteger:1 forKey:@"DataExists"];
                                  NSLog(@"Table updated");
                              }
                          }
                      }
                      else {
                          sqlite3_close(db);
                          NSAssert(0, @"Could not delete records");
                      }
                      [entries removeAllObjects];
  
                      [vrnTable performSelectorOnMainThread:@selector(reloadData) withObject:self waitUntilDone:YES];
  
                      NSString *select = [NSString stringWithFormat:@"SELECT * FROM Vehicles"];
                      sqlite3_stmt *statement;
  
                      if (sqlite3_prepare_v2(db, [select UTF8String], -1, &amp;statement, nil) == SQLITE_OK) {
                          while (sqlite3_step(statement) == SQLITE_ROW) {
                              vehicleObject = [[Vehicle alloc] init];
                              char *vrn = (char *) sqlite3_column_text(statement, 0);
                              NSString *vrnStr = [[NSString alloc] initWithUTF8String:vrn];
                              vehicleObject.vrn = vrnStr;
  
                              char *make = (char *) sqlite3_column_text(statement, 1);
                              NSString *makeStr = [[NSString alloc] initWithUTF8String:make];
                              vehicleObject.make = makeStr;
  
                              char *model = (char *) sqlite3_column_text(statement, 2);
                              NSString *modelStr = [[NSString alloc] initWithUTF8String:model];
                              vehicleObject.model = modelStr;
  
                              char *yearMade = (char *) sqlite3_column_text(statement, 3);
                              NSString *yearMadeStr = [[NSString alloc] initWithUTF8String:yearMade];
                              vehicleObject.yearMade = yearMadeStr;
  
                              [entries addObject:vehicleObject];
                          }
                      }
                      else {
                          NSAssert1(0, @"Error: Because %s", sqlite3_errmsg(db));
                      }
  
                      [self.vrnTable performSelector:@selector(reloadData) onThread:[NSThread mainThread] withObject:self waitUntilDone:YES];
                      //[self removeLodingView];
                  }
                  else {
                      [self invalidAlert];
                  }
              }
              else {
                  [self invalidAlert];
              }
          }];
      }
      else {
          [self noNetworkAlert];
      }
      [_vrnTableViewController.refreshControl endRefreshing];
  </code></pre>