web page doesn't display in iPhone (Xcode 5) - ios

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

Related

How to I Pull to refresh in webview

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.

How to use UIButton to make UIWebView go back

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];
}
}

web server show pdf in UIWebView but didFailLoadWithError in iOS run with xcode 6

PDF file error with run in xcode 6.0
It's not work ......
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(10, 10, 200, 200)];
NSURL *targetURL = [NSURL URLWithString:#"http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIWebView_Class/UIWebView_Class.pdf"];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webView loadRequest:request];
[self.view addSubview:webView];
Its going to encode .. try it. Within url 'record id_2_1_1410848039.pdf' in between record and id space count.
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
webView.delegate = self;
NSString *getURL = #"http://google.com/images/item_attachment/282/record id_2_1_1410848039.pdf";
NSString *encodedString=[getURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *webURL = [NSURL URLWithString:encodedString];
NSURLRequest *request = [NSURLRequest requestWithURL:webURL];
[webView loadRequest:request];
[self.view addSubview:webView];
webView.ScalesPageToFit = true;

display a file in UIWebView from local disk using XCode.

I have downloaded a PDF file form a web url and saved it on disk. I want to view the same file in webView. i used:
[self.navigationController pushViewController:self.fileViewController animated:YES];
i am using this code to navigate to other view controller. Following is my code in viewDidLoad:
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(10, 10, 200, 200)];
NSString *path = [[NSBundle mainBundle] pathForResource:#"myFile" ofType:#"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webView loadRequest:request];
}
Just tell me that where i am wrong. thanks in anticipation.
I have checked your code and it works. May be you need to add webview as subview to your view controller by using following code: [self.view addSubview:webView];
I hope it will help you...
- (void)viewDidLoad
{
[super viewDidLoad];
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(10, 10, 200, 200)];
[self.view addSubview:webView];
NSString *path = [[NSBundle mainBundle] pathForResource:#"myFile" ofType:#"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webView loadRequest:request];
}

Objective C: View PDF File Link With UIWebView

I am trying to view a PDF file from a server but I only get a view in black and doesn't contain anything. Here's my code:
pdfViewer = [[UIWebView alloc] initWithFrame:CGRectMake(0, 44, 768, 949)];
pdfViewer.backgroundColor = [UIColor whiteColor];
pdfViewer.delegate = self;
[sgContainer addSubview:pdfViewer];
chatSpinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
chatSpinner.frame = CGRectMake(334, 462, 100, 100);
[pdfViewer addSubview:chatSpinner];
NSString *httpSource = #"http://www.mywebsite.com/folder/subfolder/file.pdf";
NSURL *fullUrl = [NSURL URLWithString:httpSource];
NSURLRequest *httpRequest = [NSURLRequest requestWithURL:fullUrl];
[pdfViewer loadRequest:httpRequest];
If you are trying to display a PDF file residing on a server somewhere, you can simple load it to your web view directly:
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(10, 10, 200, 200)];
NSURL *targetURL = [NSURL URLWithString:#"http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIWebView_Class/UIWebView_Class.pdf"];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webView loadRequest:request];
[self.view addSubview:webView];
[webView release];
Or if you have a PDF file bundled with your application (in this example named "document.pdf"):
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(10, 10, 200, 200)];
NSString *path = [[NSBundle mainBundle] pathForResource:#"document" ofType:#"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webView loadRequest:request];
[self.view addSubview:webView];
[webView release];
Let me know if you face any problem.

Resources