I can't leave pdf with webview - ios

Does anyone know how to leave pdf with webview
this app is done with xcode,i learn it from internet
but I got a issue, when I click a download link
it would open the file in app , but I can't go back to
previous page , I can't do anything but close app & restart
So what should I add to make app go back to previous page
here is my app ,
viewcontroller.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
#property (weak, nonatomic) IBOutlet UIWebView *webview;
#end
viewcontroller.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSURL *url = [NSURL URLWithString:#"http://mywebsite/index.php"];
[self.webview loadRequest:[NSURLRequest requestWithURL:url]];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end

Related

Open an URL in UIWebView

I have an important question. I'm creating an iPhone app.
I have an UIWebView (https://www.google.de/) with goBack, goForward and reload.
Now, I want a Button e.g. Bar Button Item named Home or Homepage, to open an URL (https://www.google.de/) in this WebView, to go back to the homepage.
How can I do this? How can I "say" the button to open the link in my WebView? I ask for answer.
// ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
#property (nonatomic, strong) IBOutlet UIWebView *site ;
#end
// ViewController.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
-(IBAction)refresh:(id)sender; {
NSURL *url=[NSURL URLWithString: #"https://www.google.de/"]; NSURLRequest * requestURL=[NSURLRequest requestWithURL:url]; [_site loadRequest:requestURL];
}
- (void)viewDidLoad {
[self refresh:self];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
UIWebView has methods, goBack and goForward. You can make actions and bind it with your bar buttons to go back and forward whenever you want.
- (IBAction)goBack:(id)sender {
[_site goBack];
}
- (IBAction)goForward:(id)sender {
[_site goForward];
}
- (IBAction)goHomepage:(id)sender {
NSURL *url=[NSURL URLWithString: #"https://www.google.de/"];
NSURLRequest *requestURL=[NSURLRequest requestWithURL:url];
[_site loadRequest:requestURL];
}
To help you more, here's a tutorial on this, and if you don't want to read that tutorial, you can check their source code from here !

How to give UIWebView access to current gps location

I have a UIWebView inside my app, this loads a website which is trying to get the current gps location of the user. On Safari it presents a popup which asks if you want to give your current location to the website, on my UIWebView no such thing happens and my website is not able to get the gps location of the user. How can I accomplish this? I am new to ios developing so bear with me if this is something very easy to do, but I couldnt find an example so far.
Here is what I have so far:
ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController {
IBOutlet UIWebView *_webView;
}
#end
ViewController.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[_webView loadRequest:[[NSURLRequest alloc] initWithURL:[[NSURL alloc] initWithString:#"http://google.com"]]];
// Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)goBack:(id)sender {
if ([_webView canGoBack]) {
[_webView goBack];
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
Edit your app's info.plist and set
NSLocationWhenInUseUsageDescription "String you want to explain why you need location."

iOS UIWebView does not show the websites correct

I am creating a simple UIWebView like shown.
All works fine but the websites are corrupted. it looks like, the images arent loaded.
Curious is, that in the Browser, the same page is loading fine O_o Any Ideas?
#import "WebViewController.h"
#interface WebViewController ()
#property NSURL *adUrl;
#property (weak, nonatomic) IBOutlet UIWebView *webView;
#end
#implementation WebViewController
-(id) initWithUrl:(NSURL *)url
{
self = [super init];
if (self)
{
self.adUrl = [NSURL new];
self.adUrl = url;
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self.webView loadRequest:[NSURLRequest requestWithURL:self.adUrl]];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
Task solved. The Problem was, that an old Class which was responsible for WebCaching was disturbing the redirect and on that way it suppressed the load of baseURL objects. Thanks for givin me ideas how to solve.
Cheers

iOS 7 webview not working

when i build my apps with one page the code works fine, but when i use more than one view the app will not display the webpage, evan tough i am using identical code
in view controller.h i have this code
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController{
IBOutlet UIWebView *webview;
}
#end
in view controlled.m i have this code
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.twitter.com/GeekyLemon"]]];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
now this code works fine and is the same in the other project yet the one with multiple views won't work.
Have you checked these points :
have you set the controller as a WebViewDelegate ?
Did you linked the webview from storyboard to your IBOutlet in controller ?
When you're debugging, is the instance of your webview different from nil ?
Its hard to fix your issue without a detailed description, but try to add this method into .m file. :
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.twitter.com/GeekyLemon"]]];
}
and from viewDidLoad remove this line : [webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.twitter.com/GeekyLemon"]]];
viewDidLoad is invoking only once I suppose that this issue apper when you go to other ViewController and then go back.

UIWebView show blank to iOS dev beginner

I'm new for iOS develop. I tried to make a very simple app just show a UIWebView which display a web page:
ViewController.m:
#import "ViewController.h"
#implementation ViewController
#synthesize webView = _webView;
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSString *urlAddress = #"http://jsfiddle.net/emj365/qaQnF/embedded/result/";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:requestObj];
}
...
ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController {
UIWebView * _webView;
}
#property (nonatomic, retain) IBOutlet UIWebView * webView;
#end
UIWebView show blank. What's wrong?
There are a few different things that could go wrong. A few options you should check:
Did you check to see if the outlet was actually connected to the webview in the xib?
Implement the UIWebView delegate and check for (networking) errors

Resources