UIWebView is not responsive in iOS8 and Objective C - objective-c

The following code was working properly in iOS7, Now with iOS8 it is not getting and result. What could be the reason and the answer?
NSURLRequest *url = [[NSURLRequest alloc] initWithURL:[[NSURL alloc] initFileURLWithPath:[NSString stringWithFormat:#"https://www.facebook.com/1079798338712435"]]];
[self.webView loadRequest:url];

Use the following code and do proper connection:
NSString *stream=#"http://youtube.com";
NSURL *url=[NSURL URLWithString:stream];
NSURLRequest *request=[NSURLRequest requestWithURL:url];
[self.webView loadRequest:request];

You got a mistake: do not use -[NSURL initFileURLWithPath:] with http link
I'm sure that url is nil when running your code, and your webview loaded a NIL url, so there is nothing happened
Use -[NSURL initWithString:] instead
Good luck

I have solved it using html request instead of URL, I believe it is iOS8 bug. here is how I got the results
NSString*url2 = [NSString stringWithFormat:#"https://www.facebook.com"];
NSURL*url3 = [NSURL URLWithString:url2];
NSString*htmlString = [NSString stringWithContentsOfURL:url3 encoding:NSUTF8StringEncoding error:nil];
[self.webView loadHTMLString:htmlString baseURL:nil];

Related

UIWebView hiding when loading a full html page in, but NOT when omitting certain tags?

My UIWebView is displaying some strange behavior. When I load in a full HTML page, it just shows me a blank page. If I were, however, to load in just something like "Hi," it will display fine. my code is as follows for loading it:
NSString *html = [NSString stringWithContentsOfURL:[NSURL URLWithString: [NSString stringWithFormat:#"http://site.com/external/get.php?type=phone&url=%#", url]] encoding:NSUTF8StringEncoding error:nil];
[webView loadHTMLString:html baseURL:nil];
Assume that the html is valid, and it will always return a result if you just type in the url. That current code displays a blank UIWebView, but if I were to configure that url to just display "Hi," it would display.
You are having an encoding error. You specified, that your source would be UTF-8 encoded, which it is not.
Option 1
What is wrong with letting the UIWebView handle the request itself? It would be way easier and you don't have to mess around with encodings.
NSString *urlstring = #"http://some.url.com";
NSURL *url = [NSURL URLWithString:urlstring];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webview loadRequest:request];
Option 2
Try using NSASCIIStringEncoding instead of NSUTF8StringEncoding. Has worked out for a quick test for me. Other NSStringEncoding enumerations can be found here: http://api.monobjc.net/html/T_Monobjc_Foundation_NSStringEncoding.htm
For the Future:
Don't ignore the error.
NSError *error;
NSString *html = [NSString stringWithContentsOfURL:[NSURL URLWithString: [NSString stringWithFormat:#"http://site.com/external/get.php?type=phone&url=%#", url]] encoding:NSUTF8StringEncoding error:&error];
if (error)
NSLog(#"Error: %#", [error localizedDescription]);
In your case, this would most likely have printed out Cocoa error 261 to the console. That this means that you have a wrong encoding, can be easily found out through google and/or stackoverflow.
Also, try to debug your application, when having problems like this. The problem was the String being nil, not the WebView malfunctioning.

UIWebView doesn't load content

I don't understand why if I load the content of a UIWebView in XCode this way:
NSString *string = #"http://www.dummyurl.org/dummy.pdf";
NSURL *url = [NSURL URLWithString:string];
[my_view loadRequest:[NSURLRequest requestWithURL:url]];
everything works fine, but if a build the original string from a php script I wrote:
NSString *strURL = [NSSTring stringWithFormat:#"www.myserver.php"];
NSString *string = [[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:strURL]];
NSURL *url = [NSURL URLWithString:string];
[my_view loadRequest:[NSURLRequest requestWithURL:url]];
nothing works. I checked my script and it returns EXACTLY the original string (http://www.dummyurl.org/dummy.pdf) that works fine with the first method.
I build from a PHP script the content of a UITextView too, but that works fine.
I don't understand why this method works with the UITextView but not with the UIWebView to load the .pdf.
It may be useful
NSCharacterSet *characterSet = [NSCharacterSet whitespaceAndNewlineCharacterSet];
NSString *tempString = [string stringByTrimmingCharactersInSet:characterSet];
NSURL *url = [NSURL URLWithString:string];
[my_view loadRequest:[NSURLRequest requestWithURL:url]];
Make sure you linked the webview (IBOutlet) and the delegate.
With this lines it should load a url:
webView.delegate = self;
NSURLRequest *urlRequest;
NSString *urlToOpen = [NSString stringWithFormat:#"http://www.stackoverflow.com"];
urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:urlToOpen]];
[self.webView loadRequest:urlRequest];
Hope this helps...
I had this and it was a cache problem:
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60.0]];

ipad app opens browser in the background

Im using the openURL command to send an SMS, but it opens the safari,
can I send the command so it opens in the background??
ie, the user dont see the browser opening or the message that it gives, and stays in the app,
NSURL *url = [NSURL URLWithString: #"https://smsgw.exetel.com.au/sendsms/api_sms.php?username=xxx&password=xx&mobilenumber=0xxx&message=xxr&sender=mk&messagetype=Text&referencenumber=04"];
[[UIApplication sharedApplication] openURL: url];
Thank you
You can't have Safari open a URL for you in the background. But supposing you just want to request the URL and ignore whatever comes back, you could try:
NSURL *url = [NSURL urlWithString:#"...whatever..."];
NSURLRequest *request = [NSURLRequest requestWithURL:url delegate:nil];
NSURLConnection *connection = [NSURLConnection connectionWithRequest:request];
[connection start];
You can do this be creating a UIWebView inside your app, and calling loadRequest: on the instance, like this:
UIWebView *webView = [[UIWebView alloc] init];
webView.delegate = self;
NSURL *url = [NSURL URLWithString: #"https://smsgw.exetel.com.au/sendsms/api_sms.php?username=xxx&password=xx&mobilenumber=0xxx&message=xxr&sender=mk&messagetype=Text&referencenumber=04"];
NSUrlRequest *request = [[NSUrlRequest alloc] initWithURL:url];
[webView loadRequest:request];
This will load the URL inside the app, without sending you over to Mobile Safari. The benefit of this method over NSUrlConnection is that if you conform to the UIWebViewDelegate protocol and implement webViewDidFinishLoad: in your delegate class, you can see if the call succeeded or not.

reading excel sheet with url in Iphone sdk

I am Having a problem here.I am downloading the excel sheet using Url and have to displaying it in the web view here my problem is the Excel sheet is not displaying.
I written the code as:
NSString *str = #"";
str = [str stringByAppendingString:
#"http://databases.about.com/library/samples/address.xls"];
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:str]];
[webView loadData:data MIMEType:#"application/xls" textEncodingName:#"UTF-8"
baseURL:[NSURL URLWithString:#"http://google.com"]];
[contentView addSubview:webView];
Thank you,
Monish.
Are you able to view it using Safari on the phone or does it say "unsupported format"?
Try another file that works in Safari and then try in UIWebView.
Also see this: http://developer.apple.com/iphone/library/qa/qa2008/qa1630.html
First make sure you are able to view the xls in Safari then try code like this:
- (void)viewDidLoad {
[super viewDidLoad];
NSURL *url = [NSURL URLWithString:#"http://www.yourwebsite.com/good.xls"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
}

UIWebView Error in iPhone

I am getting this error in webview while loading this url : http://www.thumbzine.com/rssfeed.php?vol=104
"Error Domain=WebKitErrorDomain Code=102 UserInfo=0xde6ce0 "Frame load interrupted""
[webView loadRequest:[NSURLRequest requestWithURL:
[NSURL URLWithString:#"thumbzine.com/rssfeed.php?vol=104"]]];
What is this error due to ?
Thanks
Try this
NSString *urlText = [NSString stringWithString:#"http://www.thumbzine.com/rssfeed.php?vol=104"];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlText]]];