Want to how to call an external url in embedded cordova webview in iOS application. Can we escape from giving www folder and start page?
example url: http://www.stackoverflow.com
This is the snippet i tried, but since that checks for the www folder, this wont work.
CDVViewController *viewController = [CDVViewController new];
viewController.wwwFolderName = #"";
viewController.startPage = #"http://www.stackoverflow.com";
viewController.useSplashScreen = YES;
viewController.view.frame = CGRectMake(0, 0, 320, 480);
[self.view addSubview:viewController.view];
is there a way to call such external url from this end?
Thanks a bunch.
This will do the task :
[viewController.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.stackoverflow.com"]]];
Related
I have a RMS Protected pdf file something like 'sample.ppdf'.
Its being loaded from an URL.
Now When I implement the following :
UIApplication.SharedApplication.OpenUrl(new NSUrl(_documentUrl));
iPhone Safari App opens and asks me for an option to open with a particular App 'AIP Viewer'
Now when i try implementing the same with the following code :
SFSafariViewController *svc = [[SFSafariViewController alloc] initWithURL:url];
svc.delegate = self;
[self presentViewController:svc animated:YES completion:nil];
SKSafariViewController opens but is Blank.
/*! #abstract Returns a view controller that loads a URL.
#param URL the initial URL to navigate to. Only supports initial URLs with http:// or https:// schemes.
*/
- (instancetype)initWithURL:(NSURL *)URL;
Make sure you url is http://* or https://*
SFSafariViewController is compatible with version iOS 9.0+. Put the version check if the iOS version is lesser than iOS 9.0 open it directly in safari browser.
Try this,
NSURL *urlAsString = [NSURL URLWithString:[NSString stringWithFormat:#"Your_URL"]];
if ([SFSafariViewController class] != nil) {
SFSafariViewController *sfvc = [[SFSafariViewController alloc] initWithURL:urlAsString];
[self presentViewController:sfvc animated:YES completion:nil];
}
else {
[[UIApplication sharedApplication] openURL:urlAsString];
}
I use WKWebView to show a web page. When I touch a button on the page, some javascript code should work and show me an alert view. But it doesn't work. If I open the page on Safari, it works well. Here is my code
WKWebViewConfiguration *configuration = [WKWebViewConfiguration new];
configuration.preferences.javaScriptCanOpenWindowsAutomatically = YES;
configuration.preferences.javaScriptEnabled = YES;
_webView = [[WKWebView alloc] initWithFrame:self.view.bounds configuration:configuration];
self.view = _webView;
NSURLRequest *req = [NSURLRequest requestWithURL:[HPBNetworkBusiness getExamPageURL]];
[_webView loadRequest:req];
[_webView addObserver:self forKeyPath:#"URL" options:NSKeyValueObservingOptionNew context:nil];
WKWebView will not show JavaScript alerts automatically. It will be notified through
webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler: defined on WKUIDelegate. You can use the information passed in to show a native alert using UIAlertController.
Recently I just discovered a little issue.
I'm using UIWebview to load some url some times nothing really fancy, just basic init:
self.webview = [[UIWebView alloc] initWithFrame:CGRectMake(0, navBar.frame.size.height, self.view.frame.size.width, self.view.frame.size.height-navBar.frame.size.height)];
self.webview.opaque = NO;
self.webview.delegate = self;
self.webview.scalesPageToFit = YES;
[self.view addSubview:self.webview];
and i'm loading the url like this:
if(self.webview)
{
[self.webview loadRequest:[NSURLRequest requestWithURL:url]];
}
The problem that i got is when i try to redirect to tripadvisor mobile page I got a pop up saying that my version is not handled anymore and that i need to update it, the thing is that even with the last update it doesnt work...
And it's the same for ios6, 7 and 8 and only for IPHONE ...
Is there anybody who got the same problem ? and maybe fixed it ?
Thanks !
Here is the image of the popup:
I just solved by change UIWebView's user-agent
NSDictionary *dictionnary = [[NSDictionary alloc] initWithObjectsAndKeys:#"Safari iOS 8.0 - iPhone", #"UserAgent", nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:dictionnary];
put it before your webview initialize.
Hope this helps.
In my app I have a sliding view that holds UIWebView, that I want to substitute with another UIWebView that has already loaded content on user tap instead of loading the current view.
I tried just simply assign one view to another:
UIWebView* webView1 = [[UIWebView alloc] initWithFrame:frame];
UIWebView* webView2 = [[UIWebView alloc] initWithFrame:frame];
webView1 = webView2; // didn't work
Any help is highly appreciated!
If you need to keep them both around, you could just hide the one that should go away:
[webView1.superview addSubview: webView2];
[webView1 setHidden: YES];
Try this:
[webView1.superview addSubview: webView2];
[webView1 removeFromSuperview];
My solution:
Get the whole HTML string of the webView2:
NSString *htmlString = [webView2 stringByEvaluatingJavaScriptFromString: #"document.body.innerHTML"];
Load this HTML string to webView1.
I have an iOS app that needs OAuth authentication of a Facebook account, but I have to use my own server for the API calls.
So I want to open a FBLogin screen (UIWebView), with a login URL, when a certain button is clicked.
I have the following code:
FBWebViewController.h
#import <UIKit/UIKit.h>
#interface FBWebViewController : UIViewController <UIWebViewDelegate>
- (void)initFBWebView;
#end
FBWebViewController.m
- (void)initFBWebView {
NSLog(#"DetailViewController->initUIWebView {");
UIWebView *aWebView;
// init and create the UIWebView
aWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 400)];
aWebView.autoresizesSubviews = YES;
aWebView.autoresizingMask=(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
//set the web view delegates for the web view to be itself
[aWebView setDelegate:self];
//Set the URL to go to for your UIWebView
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 URL into the web view.
[aWebView loadRequest:requestObj];
//add the web view to the content view
[self.view addSubview:aWebView];
}
and in my Authorize.m file, which handles all the API calls etc.
- (void)fbLogin:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options {
FBWebViewController *webview = [[FBWebViewController alloc] init];
[webview view];
[webview initFBWebView];
}
Nothing happens. No WebView is opened. I put some debug statements in the initWithFbWebView method, and the method is called and run until the end, but no screen is showing up.
What am I doing wrong?