I was faced with parsing an unsuccessful problem only in iOS 6. The code works with previous versions of iOS 6, but does not work in iOS 6. I am trying to send a login request to the server URL. I get a response from the server in xml format. I am using NSXMLParser to parse the response. I can parse xml in iOS 3.x, iOS 4.x and iOS 5.x, but parsing is not performed on iOS 6.
I use these lines
NSXMLParser *m_parser = [[NSXMLParser alloc] initWithData:urlData]; [m_parser setDelegate:self]; BOOL parseFlag = [m_parser parse];
On iOS 6, only - (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError .
The error I get is NSXMLParserErrorDomain 68 error.
Detailed source code is given below.
-(IBAction)loginButtonPressed:(id)sender { NSMutableString *urlString = [[@"someURL" mutableCopy] autorelease]; [urlString appendString:@"loginAuthenticate"]; [urlString appendFormat:@"?username=%@",m_username.text]; [urlString appendFormat:@"&password=%@",pwd]; NSURL *url = [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; NSString *postLength = [NSString stringWithFormat:@"%d", [urlString length]]; NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease]; [request setURL:url]; [request setHTTPMethod:@"POST"]; [request setValue:postLength forHTTPHeaderField:@"Content-Length"]; [request setValue:@"text/xml; charset=utf-16" forHTTPHeaderField:@"Content-Type"]; [request setHTTPBody:[urlString dataUsingEncoding:NSUTF16StringEncoding]]; NSError *error; NSURLResponse *response; NSData *urlData; urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; NSString *responseXml = [[NSString alloc] initWithData:urlData encoding:NSUTF16StringEncoding]; if (responseXml &&[responseXml length]>0) { NSXMLParser *m_parser = [[NSXMLParser alloc] initWithData:urlData]; [m_parser setDelegate:self]; NSLog(@"urlData:%@",m_parser); BOOL parseFlag = [m_parser parse];
source share