Reputation: 43
I am facing parsing failed issue in iOS 6 only. The code is working previous versions of iOS 6 ,but not working in iOS 6. I am trying to send login request to server url. I am getting the response from server in xml format. I am using NSXMLParser to parse the response. I am able to parse the xml in iOS 3.x, iOS 4.x and iOS 5.x but parsing is failed in iOS 6.
I am using these lines
NSXMLParser *m_parser = [[NSXMLParser alloc] initWithData:urlData];
[m_parser setDelegate:self];
BOOL parseFlag = [m_parser parse];//parsing failed in iOS 6
In iOS 6 only - (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError
is called.
The error I am getting is NSXMLParserErrorDomain error 68.
Detailed source code is as 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];//parsing failed in iOS 6
if (parseFlag == 1)
NSLog(@"parseFlag = YES");//called if iOS version is less than iOS 6
else
{
NSLog(@"parseFlag = NO");//called if iOS version is iOS 6
}
.
.
}
// This delegate method is called in iOS 6 only
- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError {
NSLog(@"%@",@"parseErrorOccured");
NSLog(@"parseError:%@",parseError);
//error is NSXMLParserErrorDomain error 68
}
Upvotes: 4
Views: 417