I have a UIWebView where i load a url. But it does not load full content. I have checked all possible forums for solution but couldn't find a breakthrough yet. Any help would be really appreciated? You can try out the below url yourself. Basically, the url is supposed to contain html5 content/player.
-(void)loadPlayerUrl
{
activityIndicatorView.hidden = NO;
NSURL* nsUrl = [NSURL URLWithString:#"http://watch.nimbletv.com/tv"]
NSURLRequest* request = [NSURLRequest requestWithURL:nsUrl cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:30];
[self.playerWebView loadRequest:request];
}
However, this works perfectly in safari or any other browser.
You should create ViewControllerWebPage
Then
- (void)viewDidLoad
{
[super viewDidLoad];
self.screenName = #"Info Ekran";
NSURL *mobileCreaURL = [NSURL URLWithString:#"http://mobilecrea.com/"];
NSURLRequest *myRequest = [NSURLRequest requestWithURL:mobileCreaURL];
[mobileCrea loadRequest:myRequest];
}
Also create new view, select your new custom class (ViewControllerWebPage) and than create UIWebView
Related
My goal with this code is to simply show the html code from the url request on a Label as the app is initialized:
- (void)viewDidLoad {
[super viewDidLoad];
NSURL *url = [NSURL URLWithString:#"http://192.168.25.242:8090"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[_webView loadRequest:request];
sleep(5);
self.myLabel.text = [_webView stringByEvaluatingJavaScriptFromString:#"document.body.innerHTML"];
}
I think the url request take some time to end, so I used sleep function trying to wait for it to end and then convert the webview results into string and load on the label... But is shows nothing. When I create a button to "self.myLabel.text = [_webView stringByEvaluatingJavaScriptFromString:#"document.body.innerHTML"];" after any webview load, it does work, and the label gets the html from the webview correctly.
What should I do?
The sleep() function won't work because the webView won't be given time to load. Instead, set _webView.delegate = self; and implement -webViewDidFinishLoad:, where you should set the label text.
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
So I have a tabbed iOS app, and two of the view controllers in the app each have webViews in them. Nothing else. When these views are opened, they then call the NSURLRequest I have coded in the viewDidLoad method (as we all know). Very typical, basic, simple code.
What I am trying to do but haven't been able to figure out, is how to have these requests called and completed upon app launch, as opposed to being triggered when the view controller is viewed for the first time. It just takes too long to load.
I'm not very experienced with threads and blocks so any advice would help! I do know that all the UI stuff needs to be called on the main thread/queue. I have made an attempt at using another thread (commented out in view controller 2), so any further explanation as to what I already have would be great as well.
VC 1
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *url = [NSURL URLWithString:#"https://soundcloud.com/vanguardsf"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[_music loadRequest:request];
}
VC 2
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect screen = [[UIScreen mainScreen]applicationFrame];
_webView = [[UIWebView alloc]initWithFrame:screen];
_webView.delegate = self;
[self.view addSubview:_webView];
NSString *netGym = #"http://www.netgym.com/login.asp";
NSURL *url = [NSURL URLWithString:netGym];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[_webView loadRequest:request];
NSLog(#"%#", request );
// if (!requestQueue) {
// requestQueue = dispatch_queue_create("come.requestNetgym.load", NULL);
// }
// dispatch_queue_t requestQueue = dispatch_queue_create("come.requestNetgym.load", NULL);
// dispatch_async(requestQueue, ^{
// NSString *netGym = #"http://www.netgym.com/login.asp";
// NSURL *url = [NSURL URLWithString:netGym];
// NSURLRequest *request = [NSURLRequest requestWithURL:url];
// [_webView loadRequest:request];
// NSLog(#"%#", request );
// });
}
You don't have to use GDC to send asynchrounus NSURLRequests - they are asynchronous if You don't use them synchronously on purpose.
You can start the requests in this method:
https://developer.apple.com/library/ios/documentation/uikit/reference/uiapplicationdelegate_protocol/Reference/Reference.html#//apple_ref/occ/intfm/UIApplicationDelegate/application:willFinishLaunchingWithOptions:
This is first place in application when You can execute a code just after launching is finished. You will save some time (little I suppose - this looks like a simple app).
I think that better solution is to cache the downloaded website data. In this case You will download the data first time You enter the app and the second time You will display downloaded content. In the background You will check if website has changed. If so You update the content.
I want to create an ios application which incuding a UIWebview. I saw so many tutorials that saying how to load webview when start the application. But what I want is when user click on a link in one View,the web page should be loaded in seperate View. This is the code in my button click event.
`
-(IBAction)visitWeb:(id)sender{
web *wb=[[web alloc]initWithNibName:nil bundle:nil];
[self presentModalViewController:wb animated:YES];
[wb release];}
This is in web
`
- (void)viewDidLoad {
NSString *urlAddress = #"http://www.google.com";
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[webView loadRequest:requestObj];
[super viewDidLoad]; }
But it not display anything. Just display the empty UIWebView What is the reason for it.plz give me a solution with the code.
Thanks,
I thought it would be easy to load in a html file from my resources into a UIWebView, but it looks like it requires something extra that I'm not doing. So far I have in my viewDidLoad in my controller:
NSURL *url = [NSURL URLWithString:#"radialGradient.html"];
NSURLRequest *req = [NSURLRequest requestWithURL:url];
[webView loadRequest:req];
webView.frame = CGRectMake(0, 0, 768, 1024);
I've tried regular web addresses (google.com) and it works fine. But with the file in my sources it just renders a white blank screen.
Two things:
1)
What you have now is not a URL. It's just a filename. You need to be prepending a "file:///" in front of that radialGradient.html.
2)
And, you'll likely also need to put in a resolvable path to radialGradient.html Right now your app doesn't know where to look for it.
Something like:
NSURL * resourcePathURL = [[NSBundle mainBundle] resourceURL];
if(resourcePathURL)
{
NSURL * urlToLoad = [resourcePathURL URLByAppendingPathComponent: #"radialGradient.html"];
if(urlToLoad)
{
NSURLRequest * req = [NSURLRequest requestWithURL: urlToLoad];
[webView loadRequest: req];
}
}