I am new learning.
I made a UIWebView on Xcode.
Refresh Code simulator is working but not working on the phone.
How to ı can run?
Here is code
-(void)viewDidLoad {
NSString *fullURL = #"http://mysite.com.tr/report";
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
webView.delegate = (id)self;
[webView loadRequest:requestObj];
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
[refreshControl addTarget:self action:#selector(handleRefresh:) forControlEvents:UIControlEventValueChanged];
[webView.scrollView addSubview:refreshControl];
}
-(void)handleRefresh:(UIRefreshControl *)refresh {
// Reload my data
NSString *fullURL = #"http://mysite.com.tr/report";
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
[refresh endRefreshing];
[super viewDidLoad];
}
Your code is working fine.
remove
[super viewDidLoad];
And in info.plist file add a property.
Note: Allow arbitrary Loads to YES is not recommended though.Hope you'll figure it out by yourself.
Related
Same url in run in lower then iOS10 (ex. iOS8,iOS9) work properly.
-(void) loadUrl
{
NSString *urlAddress = #"http://myurl.com";
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[detailWebView loadRequest:requestObj];
}
I tried your code and it works fine in ios 10 and xCode 8.
I used this,
-(void) loadUrl
{
NSString *urlAddress = #"http://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.
[self.webView loadRequest:requestObj];
}
And call this method where you want using [self loadUrl];
Add URLSchemes in your plist file for your url.
I am getting webview like,
Your code is not wrong.
Hope this will help you.
In apps that run in iOS 8 and later, use the WKWebView class instead of using UIWebView.import webkit.h and use this code
#import <WebKit/WebKit.h>
WKWebViewConfiguration *theConfiguration = [[WKWebViewConfiguration alloc] init];
WKWebView *webView = [[WKWebView alloc] initWithFrame:self.view.frame configuration:theConfiguration];
NSURL *nsurl=[NSURL URLWithString:#"http://www.apple.com"];
NSURLRequest *nsrequest=[NSURLRequest requestWithURL:nsurl];
[webView loadRequest:nsrequest];
[self.view addSubview:webView];
I have a UIWebView and i want when users go to a link in it they can go back hereis my webview code
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 430)]; // x is width,y is hght
NSString *urlAddress = #"http://livewiretech.co.nf/ NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
[self.view addSubview:webView];
And i have a UIButton and the code for it is
-(void) backButtonPressed {
//Back code here
}
something like this should get you going
#property (nonatomic, strong) UIWebView * webView;
....
webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 430)]; // x is width,y is hght
NSString *urlAddress = #"http://livewiretech.co.nf/";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
[self.view addSubview:webView];
-(void) backButtonPressed {
if ([webView canGoBack]) {
[webView goBack];
}
}
i want to display a web page in my app but it doesn't work
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIWebView *web1 = [[UIWebView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 640.0)];
NSURL *URL = [NSURL URLWithString:#"http://google.com"];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:URL];
web1.delegate = self ;
[web1 loadRequest:requestObj];
[self.view addSubview:web1];
}
just replace this method
NSURL *URL = [NSURL URLWithString:#"http://google.com"];
in to
NSURL *URL = [NSURL URLWithString:#"https://www.google.com"];
i tried your code is
UIWebView *web1 = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 300)];
NSURL *URL = [NSURL URLWithString:#"https://www.google.co.in"];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:URL];
[web1 loadRequest:requestObj];
[self.view addSubview:web1];
the output is
I have created an app which is a web browser. Whenever I enter any URL in text field it goes to the required web page. I have included an UIWebView to display webpage. By default google website is opened. But when I select any website from google I want to display that URL in the textfield. How do I do it?
- (void)viewDidLoad
{
[super viewDidLoad];
self.myTextField.text = #"http://www.google.com";
NSURL *myURL = [NSURL URLWithString:#"http://www.google.com"];
NSURLRequest *myRequest = [NSURLRequest requestWithURL:myURL];
[_myWebView loadRequest:myRequest];
self.myTextField.delegate = self;
}
You can do like this
- (void)viewDidLoad
{
[super viewDidLoad];
self.myTextField.text = #"http://www.google.com";
NSURL *myURL = [NSURL URLWithString:#"http://www.google.com"];
NSURLRequest *myRequest = [NSURLRequest requestWithURL:myURL];
[_myWebView loadRequest:myRequest];
_myWebView.delegate = self;
self.myTextField.delegate = self;
}
- (void)webViewDidFinishLoad:(UIWebView *)webView;
{
NSURL *requestURL = [webView.request URL];
txtView.text = [requestURL absoluteString];
}
I have an application at the moment that basically opens a url depending on what the user has typed into a textbox. The logic for this is as such:
Predetermined beginning + User Input + Predetermined End
So basically my URL is 3 concatenated strings. Now I know the link is being formed properly (I've put the same snip of code into a label) but nothing happens when I press the button to load the webview.
It works perfectly fine when I use the below, where I explicitly type https://google.com
- (IBAction)btnSearchPress:(id)sender {
[self.view endEditing:YES];
[super viewDidLoad];
NSString *fullURL = #"https://google.com";
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[_wbView loadRequest:requestObj];
}
However nothing happens when I use this code which includes my concatenated url:
- (IBAction)btnSearchPress:(id)sender {
[self.view endEditing:YES];
[super viewDidLoad];
NSString *fullURL = [NSString stringWithFormat:#"%#%#%#", _urlPrefix.text,_txtInput.text, _urlSuffix.text];
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[_wbView loadRequest:requestObj];
}
Any help would be much appreciated.
UPDATE: I'm fairly sure having the stringWithFormat is causing this problem just unsure how to get around it.:
Check if fullURL starts with http:// or https://, if not prefix that.
- (IBAction)btnSearchPress:(id)sender {
[self.view endEditing:YES];
[super viewDidLoad];
NSString *fullURL = [NSString stringWithFormat:#"%#%#%#", _urlPrefix.text,_txtInput.text, _urlSuffix.text];
if ( ! ([fullURL hasPrefix:#"http://"] || [ fullURL hasPrefix:#"https://"]) ) {
fullURL = [NSString stringWithFormat:#"http://%#", fullURL ];
}
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[_wbView loadRequest:requestObj];
}