IOS App Development WebView - ios

I am trying to make an iOS app and I need to add a web view but the issue is I get an error:
Duplicate declaration of method 'viewDidLoad'
- (void)viewDidLoad {
[super viewDidLoad];
NSString *fullURL = #"http://google.com";
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[_viewWeb loadRequest:requestObj];
}
I am testing with google for now and when I develop the web site for the web view I will put the website in.

objective-C does not support method overloading, so you have to use different method names.I am sure you have two viewDidload methods implemented in your .m class so please try to remove one method
i have attached screen shot for your reference try to remove any one viewDidLoad method

Related

iOS view PDF from a given url inside of an app

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

Completing NSURLRequest upon app launch

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.

UIWebView does not initially load certain URLs

Having such a bizarre issue with the UIWebView and I haven't been able to find a solution online. I have an iPad app that has a web view in it. Upon first install and run of the app, I try to load an education website. The web view just hangs and times out. I kill the app, I run it again, and it loads just fine. This one works fine which is also part of the education website. I'm pulling my hair out!
Some code:
-(void)viewDidAppear:(BOOL)animated
{
NSURL *websiteUrl = [NSURL URLWithString:#"http://my.tac.edu.au"];
NSURLRequest *urlRequest = [[NSURLRequest alloc]initWithURL: websiteUrl];
[self.webView loadRequest:urlRequest];
}
Works fine with www.tac.edu.au. I don't know what it is about that URL that makes it hang only when the app is first installed. You stop it, run it again (without uninstalling) and it comes up just fine. Any help would be appreciated.
:)
instead of view did appear , write the code in view will appear
-(void)viewWillAppear:(BOOL)animated
{
NSURL *websiteUrl = [NSURL URLWithString:#"http://my.tac.edu.au"];
NSURLRequest *urlRequest = [[NSURLRequest alloc]initWithURL: websiteUrl];
[self.webView loadRequest:urlRequest];
self.webview.delegate = self;
}
- (void)webViewDidStartLoad:(UIWebView *)webView{
//Start Activity Indicator
}
- (void)webViewDidFinishLoad:(UIWebView *)webView{
//End activity indicator
}

Is it possible to resume where you last were in UIwebView Xcode 5

Hi im am currently building a app where i have multiple webViews with different sites. My question is if you can when you click a view and surf on it and the switch to a different view and the back to the first view resume where you were and not having to start over just because the view reloaded? I now the question is kind of messy but if you could help it would be awsome! im using a regular UIvewView
NSURL *url = [NSURL URLWithString:#"https://www.mywebsite.com"];
NSURLRequest *requestURL = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestURL];
Ok, you can just save the last url you went to and reload that page? I think you can do that with NSUserDefaults.
No need to use NSUserDefaults or state restoration if you're just looking to save the page address between views. (If you're looking to save the data between app uses, then yes, you could store the url string using NSUserDefaults.)
To store the value in your app delegate for global access, declare the variable in your app delegate's .h:
#property (nonatomic) NSUrl *currentUrl;
To access the variable in a class, create an instance of the app delegate in the .m:
#import "ViewController.h"
#import "AppDelegate.h"
#interface ViewController ()
#end
#implementation ViewController
AppDelegate *mainDelegate;
- (void)viewDidLoad
{
mainDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
Then instead of using:
NSURL *url = [NSURL URLWithString:#"https://www.mywebsite.com"];
NSURLRequest *requestURL = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestURL];
initially set the currentUrl value before webView is ever opened:
mainDelegate.currentUrl = [NSURL URLWithString:#"https://www.mywebsite.com"];
and prior to each webView open, initialize the NSUrlRequest to:
NSURLRequest *requestURL = [NSURLRequest requestWithURL:mainDelegate.currentUrl];
Finally, to store the current address of each webView upon closing, use:
mainDelegate.currentUrl = webView.request.URL;

How to load a UIWebView when click a button in another view in ios

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,

Resources