I am making a IOS App and i want to open a PDF in div tag of my html file.I have found a code which works well on windows but it is not working in iOS app. In iOS app it just show the image of the first page.
Open the pdf in Webview and keep a button on top right corner (or anywhere) You want it.. And their you can write code for dismissing the WebView.
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(10, 10, 300, 300)];
NSString *path = [[NSBundle mainBundle] pathForResource:#"documentName" ofType:#"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webView loadRequest:request];
[self.view addSubview:webView];
And in Done Button Action Just remove the WebView
Related
1st StackOverflow question for me...
!! Objective-C !!
I'm in the process of updating an old app and am working on help screens.
I chose to display some useful How-tos through some html mainly for the ease of formatting the text (bullet points, colors, bold, underline etc...).
Since the app is a bit complex, The help screens are in a total of 3:
A main info webpage that links to 2 other detailed pages.
Tha app is localized in English (Base) and French.
Once the setup was complete, and with everything working fine, I went ahead and localized the base html files.
Now, they are neatly placed in the Base.lproj and fr.lproj files.
But when when I tap on a link to another page from the main WebView, nothing happens !
Any ideas ?
Thanks
Here are some bits of code I'm using:
In the .h file :
#interface howToViewController : UIViewController <WKUIDelegate>
{
WKWebView *infoText;
NSString *uRLString;
}
#property (nonatomic, retain) WKWebView *infoText;
In the .m file: (had to programmatically create the WKWebView because of the known Xcode 9 bug when creating it through Storyboards)
- (void)viewDidLoad
{
[super viewDidLoad];
WKWebViewConfiguration *theConfiguration = [[WKWebViewConfiguration alloc] init];
WKWebView *aWebView = [[WKWebView alloc] initWithFrame:self.view.frame
configuration:theConfiguration];
aWebView.UIDelegate = self;
self.infoText = aWebView;
NSURL *url = [[NSBundle mainBundle] URLForResource:#"infoHTML" withExtension:#"html"];
NSString *html = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
NSURL *baseUrl = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
[infoText loadHTMLString:html baseURL:baseUrl];
[self.view addSubview:infoText];
}
In the html file, the links that no longer work once the files are localized:
<p>3/ More information is available for the respective tabs by pressing the following links :</p>
<ul><li>Limitations
</li></ul>
<ul><li>Fueling
</li></ul>
Working code from one of my apps. I'm using NSURLRequest and WKWebView's loadRequest instance method. I'm not sure what's going wrong with your use of loadHTMLString:baseURL: but I think it may have something to do with the value you're passing for the baseURL argument. Have you cleared the console, then single-stepped over that line of code to see if you're getting any message in the console?
NSURL *url = [[NSBundle mainBundle] URLForResource: pageString withExtension: #"html"];
NSURLRequest *request = [NSURLRequest requestWithURL: url];
[webView loadRequest: request];
I am loading html content in UIWebview (iPhone6) and the content has actionable buttons. Upon pressing one of the buttons a pop up shows up in the middle of the content (content is approximately 6-7 pages long). As a result, user is unable to see the popup as she is on the first screen. Earlier, I thought it was content's issue, but on android, the pop up comes on the middle of the first page.
-(void) loadScorm {
NSString *scormUrl = self.content.media.scormUrl;
scormUrl = [NSString stringWithFormat:#"%#%#", #"https:" , scormUrl];
NSURL *url = [NSURL URLWithString:scormUrl];
NSString *body;
body = //constructed body
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL: url];
[request setHTTPMethod: #"POST"];
[request setValue:#"application/x-www-form-urlencoded" forHTTPHeaderField:#"Content-Type"];
[request setHTTPBody:[body dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]];
self.webView.scalesPageToFit = YES;
[self.webView loadRequest:request];
self.webView.frame = self.webViewContainer.frame;
}
I also read that javascript for UIWebView is enabled by default. What am I missing? Any pointers would be appreciated.
PS: Can't share the screenshot as the content is classified.
How you create your UIWebView via Code or IBOutlet.
If you are created your webView via IBOutlet then you have to check some webView property in Storyboard like
Then your webView will take Events.
And if you are created your UIWebView via code then write this code
[your_webView_Object setDataDetectorTypes: UIDataDetectorTypeAll];
[webview loadHTMLString: [NSString stringWithFormat:#"<div id ='foo' align='justify' style='font-size:22px; font-family:helvetica; color:#ffffff';>%#<div>",[jsonObject objectForKey:#"msg"]] baseURL:nil];
Hope you will find useful
Apparently, this was an issue from the side of content creator. The person didn't include the support of Safari and Chrome on iOS platform and hence, these issues.
I would like to use external file .html to use WKWebView. Or is there a solution without external file ? All is working good on simulator, but not on device...
Here is my code :
NSString *path = [[NSBundle mainBundle] pathForResource:#"myHTML" ofType:#"html"];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
WKWebViewConfiguration *theConfiguration =
[[WKWebViewConfiguration alloc] init];
[theConfiguration.userContentController
addScriptMessageHandler:self name:#"interOp"];
_webView = [[WKWebView alloc] initWithFrame:self.view.frame
configuration:theConfiguration];
[_webView loadRequest:request];
[self.view addSubview:_webView];
I've read this topic : WKWebView not loading local files under iOS 8
I don't want to use a server. I'm using Objective-C, and I want that it works on only one view, not like the https://github.com/shazron/WKWebViewFIleUrlTest project with 2 views and button and I need to have connexion with internet in the page (read iFrame).
What have I to do ?
You have to copy all your web files to the app's NSTemporaryDirectory and call your index.html from there. Works fine on iOS 8.3 for me.
I have been searching through questions trying to find an answer but I can't seem to figure out what I am doing. I want to display just a section of my HTML in webview.
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 640.0)];
NSURL *URL = [NSURL URLWithString:#"http://stackoverflow.com"];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:URL];
webView.delegate = self ;
[webView loadRequest:requestObj];
[self.view addSubview:webView];
This works perfectly displaying the whole webpage. But lets say I want to just display a certain div, what do I have to do?
I have tried adding in getElemntByID and getElementsByClass but it doesn't seem to work for me..
the answer of your question.
NSString *htmlPage = #"<html><body><h1>StackOverFlow</h1></body></html>";
[yourWebView loadHTMLString:htmlPage baseURL:nil];
I have a array in the Objective-C source.
I have to display the contents of array on onclick of a button in Html or Javascript, how to link the Html file in objective C in xcode.
You can use the uiwebview to display the html content in objective-c
Create a webview in xib and connect it to IBoutlet UIWebView *web;
Then write this code wherever you want.And the file should be in the resources folder
NSString *path1 = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:#"filename"] ofType:#"html"];
NSURL *url1 = [NSURL fileURLWithPath:path1];
NSURLRequest *request1 = [NSURLRequest requestWithURL:url1];
[web loadRequest:request1];