error on line 2 at column 59: SystemLiteral " or ' expected - ios

I am getting such error in my iOS application when I am going to open some web pages using buil-in web view engine (based on Safari but Safari works fine):
This page contains the following errors: error on line 2 at column 59:
SystemLiteral " or ' expected. Below is a rendering of the page up to
the first error.
(nothing is rendered).
The funny thing is that these websites can be opened on iPhone's version of my app but not on iPad.
Looking into the Internet I found hundreds of thousands websites which cannot be handled by google robots - when I search in google:
"59: SystemLiteral " or ' expected"
it lists search results but all found websites' descriptions shows my error. However when I open any of them they are rendering fine on desktop browser and iOS Safari.
Anybody knows what may be the reason of that? Non of websites opened from this google search can be rendered in my app on iPad - all shows the same error.
I also tried debug it using Mac's Safari Developer mode but it does not give any hint.
Update: I prepared a minimal project, added UIWebView controller and it shows the same error.
ViewController.h:
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
#property (weak, nonatomic) IBOutlet UIWebView *webView;
#end
ViewController.m:
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *fullURL = #"http://catalog.llc.lib.ms.us/polaris/";
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[_webView loadRequest:requestObj];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
#end
I also tried few web pages with this code (all from google search I mentioned above), they show also different erros, like "error on line 1077 at column 9: Opening and editing tag mismatch: META line 0 and head." - this comes from http://www.lucindalayton.com/home/?ID=15449 but still they cannot be rendered.

Looking at the response from that web site, it has a blank line at the start of the response, which seemed a little curious. In my first attempt, I trimmed that whitespace:
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *fullURL = #"http://catalog.llc.lib.ms.us/polaris/";
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
if (!data) {
NSLog(#"%s: sendAsynchronousRequest error: %#", __PRETTY_FUNCTION__, connectionError);
return;
}
NSString *html = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
html = [html stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
[_webView loadHTMLString:html baseURL:url];
}];
}
But I later noticed that you don't have to trim the whitespace, but rather merely using loadHTMLString seemed to be enough.
I'm unclear as to why Safari handles this properly, as does the iPhone web view, but not the iPad web view. But this seems to get around it.

Rob, thanks from hint but in my case it was something else. I found breakthrough analysing communication between browser and server using some test web page. I will explain it in details:
The problem is related to user agent and mime type.
My application was containing in user agent string, among other things, "Mobile/[somenumber] Safari Version/[someversionnumber]"Some servers are very strict what comes in user agent and for mobile Safari-based browsers are expecting some Safari webkit version so the proper notation should be "Mobile/[somenumber] Safari/[someverionnumber] Version/[someversionnumber]"
Notation affects behavior of the server - it sends different mime type (Content-Type). For websites I mentioned in the qestion when user agent is improper "Content-Type" is set by server to "application/xhtml+xml", but when is proper it is "text/html" which is rendered without any problems. Html code sent in both cases is exactly the same.
Anyway, for me it is still hard to say if it is server site fault, which lets sending "application/xhtml+xml" content type to mobile device, or webkit which should handle such code anyway or very strict user agent notation.

Related

iOS view PDF from a given url inside of an app

I want to open and show a pdf file from a given url (somewhere in the internet) and view it in my iOS application. Could you please tell me what are the possible approaches to this problem, and list their advantages and disadvantages / limitations? I've heard about UIWebView, are there any other options?
My suggestion is using the webview.
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
NSURL *url = [NSURL URLWithString:#"https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/ProgrammingWithObjectiveC.pdf"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[self.webview loadRequest:request];
}
If you want to more information please refer the follwing link as well
https://developer.apple.com/library/ios/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_pdf/dq_pdf.html

IOS App Development WebView

I am trying to make an iOS app and I need to add a web view but the issue is I get an error:
Duplicate declaration of method 'viewDidLoad'
- (void)viewDidLoad {
[super viewDidLoad];
NSString *fullURL = #"http://google.com";
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[_viewWeb loadRequest:requestObj];
}
I am testing with google for now and when I develop the web site for the web view I will put the website in.
objective-C does not support method overloading, so you have to use different method names.I am sure you have two viewDidload methods implemented in your .m class so please try to remove one method
i have attached screen shot for your reference try to remove any one viewDidLoad method

UIWebView displays blank page on form submit

I'm an iOS newb (.NET professional), so this may be a simple issue but I couldn't find anything through the SO search or Google (and maybe not looking for the right terms).
I'm writing an app that displays information from a DD-WRT router through it's web interface. I have no problem displaying the initial page and navigating through any of the other pages, but if I make any change on a form (and it redirects to apply.cgi or applyuser.cgi), the UIWebView is blank - it's supposed to display the same page, with the form submission changes. The site works fine in Mobile Safari, which I find intriguing, but I guess UIWebView isn't totally the same.
I think the iOS code is pretty standard for display a webpage, but I'll list it below. I can't give you access to my router because, well, that's not a good idea :) Hopefully someone with a DD-WRT router can help (or know what my issue is anyway).
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *sURL = #"http://user:pass#XXX.XXX.X.X";
NSURL *url = [NSURL URLWithString:sURL];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:request];
self.webView.delegate = self ;
}
And I'm doing a few things with Javascript in the webViewDidFinishLoad method, but I know that's not the culprit because it still happens when I comment it out.
Well I figured out the problem on my own. I think part of it was putting the username & password in the URL (which was just a temporary measure) because I found that method provided the same results in mobile Safari and desktop Chrome.
So I added MKNetworkKit to my project that provided a simple way to add authentication to my request, and found I had to make a specific request to POST the data, then reloaded the page the to see the changes.
In the (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType method, I check if ([request.HTTPMethod isEqualToString:#"POST"]) and do this:
NSString *sPostData = [[NSString alloc] initWithData:request.HTTPBody encoding:NSUTF8StringEncoding];
NSArray *aPostData = [sPostData componentsSeparatedByString:#"&"];
NSMutableDictionary *dPostData = [[NSMutableDictionary alloc] init];
//i don't know if this is the best way to set a dictionary, but it works
for (id apd in aPostData)
{
NSString *key = [apd componentsSeparatedByString:#"="][0];
NSString *val = [apd componentsSeparatedByString:#"="][1];
[dPostData setValue:val forKey:key];
}
MKNetworkEngine *engine = [[MKNetworkEngine alloc] init];
MKNetworkOperation *op = [engine operationWithURLString:[request.URL description] params:dPostData httpMethod:#"POST"];
[op setUsername:#"myUserName" password:#"myPassword" basicAuth:YES];
self.postedRequest = TRUE; //a bool I set so, when it comes to webViewDidFinishLoad, I reload the current page
[op start]; //send POST operation

UIWebView staying blank until I hard code the URL

I am writing an App where I pass a Link as a NSString from a TableView to my DetailView. The String gets passed correctly, as I can see it in the log. The problem is, that the WebView just stays blank; unless I hard code any URL in. Even the ones that I can see in the log by just copy pasting them. What am I missing? Any help is greatly appreciated. Here's a sample log output and my code. I also checked this thread, where the guy hab the exact same problem as me, but none of the solutions posted there where helpful. UIWebView not loading URL when URL is passed from UITableView
2013-06-17 13:19:52.147 Feuerwehr[1661:c07] http://oliverengelhardt.de/ffw_app/Einsaetze/GB0505/index.html
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *urlString = url;
NSURL *myURL = [NSURL URLWithString:urlString];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:myURL];
[webView loadRequest:requestObj];
NSLog(urlString);
}
I think you stringUrl is nil when it loads (so it doesn't get passed. Break point view did load and see the value of the urlstring
Based on what you've said, your url isn't formatted correctly
i think you are missing delegate
self.webView.delegate = self;

Wrong base URL in UIWebView

I'm working on a payment system that runs in a UIWebView. The user completes a form on one site, and is taken to a payment gateway to process their card information. Once the payment has been processed, the user is taken back to a confirmation page on the first site.
The sites work as expected when tested in a normal browser, or even Mobile Safari. The sites are black boxes, and I can't change anything inside them. Apparently, the sites use relative URLs, and my issue occurs because my UIWebView is trying to load a page on the second domain with the base URL from the first domain.
For example,
User posts form from http://theform.com/page
User is taken to http://theform.com/OrderCC.aspx?orderRef=e59d7f53a693472cad8a76dd8fb64
In the second step, the user should have been taken to http://thepaymentgateway.com/OrderCC.aspx...
I'm trying to intercept requests to the wrong base URL, and reroute them to a correct one like this:
-(BOOL)webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest*)inRequest navigationType:(UIWebViewNavigationType)inType {
NSString *wrongURL = #"http://theform.com/OrderCC.aspx";
NSString *request = [[inRequest URL] absoluteString];
NSString *data = [[NSString alloc] initWithData:[inRequest HTTPBody] encoding:NSASCIIStringEncoding];
if ([request length] >= 33 && [[request substringWithRange:NSMakeRange(0, 33)] isEqualToString:wrongURL]) {
[webView loadData:[inRequest HTTPBody] MIMEType:#"text/html" textEncodingName:#"UTF-8" baseURL:[NSURL URLWithString:[NSString stringWithFormat:#"https://thepaymentgateway.com/OrderCC.aspx%#", [request substringFromIndex:33]]]];
return NO;
}
return YES;
}
After this runs, it seems my UIWebView is just displaying a blank page containing the POST data string. Where am I going wrong?

Resources