I'm trying to load documents into my app for display and this works if they're stored locally but not from the server. I'm testing with MAMP. Here's my viewDidLoad method:
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *myUrl = [NSURL URLWithString:#"http://localhost:8888/FilesForApp/Docs/MS.doc"];
NSURLRequest *myRequest = [NSURLRequest requestWithURL:myUrl];
[_webView loadRequest:myRequest];
}
Can anyone point tell me if there's something missing from this?
-EDIT-
Forgot to add, it doesn't crash, just shows a plain, white display.
Make sure you can access that doc through your web browser(make sure the doc exists).
Try to add the http:// prefix.
Don't forget to add _webView as subView to your view.
Don't forget to set the _webView's frame.
Related
I want to use a simple WebView to fetch the content of a website, which includes JavaScript. I don't want to really show the WebView, I only want to get the source code of the site. The view where I will load the request from, is not in the window hierarchy. The method is getting called from another view.
Something like this:
MainView.m:
[[HelperView alloc]LoadWebview];
HelperView.m:
-(void)LoadWebview {
webView = [[UIWebView alloc]init];
[webView setDelegate:self];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.google.com/"]]];
[self.view addSubview:webView];
}
Is it possible to use the delegate methods from this WebView in a view, which is not in the window hierarchy, or is there a better way to solve this problem?
If all you need is to get the source code then try this:
-(void)loadWebview{
//Create an NSURL object
NSURL *url = [NSURL URLWithString:#"http://www.yourWebsiteHere.com"];
//Create a string to hold the source code
NSString *sourceCode= [NSString stringWithContentsOfURL:url];
//Do what you want with the source code here!
}
I m just trying to fix all the contents of html according to the device screen.
I have to put html data at proper place for iPhone & iPad in webview.
Please help me!!!
I am going to assume that this question is a very basic one.
Suppose that you have placed a UIWebView in a view in your storyboard, and you have set layout constraints so that the UIWebView fills the view.
Then
Add an IBOutlet to your view controller, and connect it to the web view.
In the view controllers viewDidLoad: method, tell the web view what to display. Here is an example:
-(void)viewDidLoad {
[super viewDidLoad];
NSURL* url = [NSURL URLWithString:#"http://www.apple.com"];
NSURLRequest* r = [NSURLRequest requestWithURL:url];
[_webView loadRequest:r];
}
This loadRequest: call is asynchronous, meaning that the page may not show up immediately.
If this is not answering your question, please add more information.
I have been using AMSlidemenu with multiple AMSlideMenuContentSegues.
They all work fine at the moment as they just display a label.
The first view controller I have added a web view and given it its own custom class .h and .m file which point to a url but every time I launch the application crashes.
.....
- (void)viewDidLoad
{
NSURL *url = [NSURL URLWithString:#"http://google.com"];
NSURLRequest *requestURL = [NSURLRequest requestWithURL:url];
[websiteWebview loadRequest:requestURL]; **Thread 1: Breakpoint 1.1**
[super viewDidLoad];
// Do any additional setup after loading the view.
}
......
I dont understand whats happening ... I m a novice when it comes to Xcode so any help will be appreciated.
I hope I have contextualized my problem.
I have a UIWebView that loads a PDF document, like this:
NSURL *myUrl = [NSURL URLWithString:#"http://www.site.com/myPDF.pdf"];
NSURLRequest *myRequest = [NSURLRequest requestWithURL:myUrl];
// Clear Cache, to insure prompt update of PDF
[[NSURLCache sharedURLCache] removeCachedResponseForRequest:myRequest];
[myWebView loadRequest:myRequest];
When my internet connection is off, i get nothing. Just a blank UIView. Is there any way i can detect when there is not internet connection, or check if the URLContents is empty? I am trying to call a method -(void)showErrorText to show text in the center screen. How would i do this? (I got the method complete, just not the internet check). THANKS.
You can try to set the delegate of the webView to self and implements the webView:didFailLoadWithError and the others delagate methods tout have more details.
I have a WebView in my app that works fine but very slow to load. Is there a way to actually start loading the web view as soon as the app starts?
Thanks
[EconCalWebView setDelegate:self];
// Do any additional setup after loading the view.
NSURL *myURL = [NSURL URLWithString:#"http://www.forexyard.com/en/calendar.iframe?zone_id=9493"];
NSURLRequest *myRequest = [NSURLRequest requestWithURL:myURL];
[EconCalWebView loadRequest:myRequest];
You can write your code for loading webview in:
applicationDidFinishLaunching method available in AppDelegate Class.
Here you require to load your viewController first and then load webView.
Please find more details at : UIApplicationDelegate