I have a application on iPad 1 and a PDF with several links.
The client will click on that link and I need to get its variables values and use it on my application.
Is it possible?
Thanks in advance
Use a UIWebView and load the PDF in it. Something like this (note - it's untested but should get you on the right track!):
NSString* basePath = [[NSBundle mainBundle] bundlePath];
NSURL* baseurl = [NSURL fileURLWithPath:basePath];
[self.webView loadData:MIMEType:#"application/pdf" textEncodingName:nil baseURL:baseurl];
Related
I'm saving a NSURL given from a save panel in the user preferences. I'm wondering how to see the path of the URL even if the device on which the file resides is not available, i.e. [NSURL URLByResolvingBookmarkData:options:bookmarkDataIsStale:error:] returns nil.
The last known path of a bookmark can be retrieved like so:
NSDictionary *values = [[NSURL resourceValuesForKeys:#[NSURLPathKey]
fromBookmarkData:bookmarkData]
NSString *path = [values objectForKey:NSURLPathKey];
I made a full writeup of this.
I am creating a Cocoa web browser, and I noticed that if the webview loads a nil location, it just loads about:home. Since I have not set it, the page just appears white. Is there a way I can change what about:home looks like. Even if it is a simple .rtf file or something.
I looked around, but don't see any way to do this. Am I suppose to create a NSURL and set it to whatever file?
Thanks. Oh, and if code is ever needed, I would be glad to add it.
Try something like this:
// Inside your App Delegate
-(void)applicationDidFinishLaunching:(NSNotification *)notification {
// Assuming WebView is called myWebView
NSString *currentURL = [myWebView mainFrameURL];
if(!currentURL) {
NSString *homeResource = [[NSBundle mainBundle] pathForResource:#"home" ofType:#"html" inDirectory:#"default"];
NSURL *homeURL = [NSURL fileURLWithPath:homeResource];
NSURLRequest *request = [NSURLRequest requestWithURL:homeURL];
[myWebView loadRequest:request];
}
}
You'll need to have a pre-made file called home.html within a folder called default located in the Resources section of your project.
I suppose this isn't exactly replacing about:home, but you can always check for about:home and handle that appropriately as well.
Right, so far I've got this for loading up a HTML file from within my app:
NSString *path1 = [[NSBundle mainBundle] pathForResource:#"file" ofType:#"html"];
NSString *html = [NSString stringWithContentsOfFile:path1 encoding:NSUTF8StringEncoding error:nil];
[[webView mainFrame] loadHTMLString:html baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle]bundlePath]]];
Which works loading the file up into the app's WebView. But I want to change some values in the HTML (or PHP if it works by using $_REQUEST/$_GET), for example, I have a table with some text in it and I want to change this text from an NSString etc.
How would I go about this?
You can execute JavaScript on UIWebView, if you need to do that dynamically.
Or, if you want to refresh the whole page, you can modify string loaded from file according to your preferences.
I've looked at quite a few of the related questions and cannot find a similar problem or a solution so my apologies if there is a duplicate out there somewhere.
Anyway, I'm trying to generate a file's NSURL to use with an NSXMLDocument. I have the following components:
const NSString * PROJECT_DIR = #"~/SP\\ BB/";
const NSString * STRINGS_FILE = #"Localizable.strings";
and construct the URL like so:
NSURL * stringsURL = [NSURL fileURLWithPath:[[NSString stringWithFormat:#"%#%#",PROJECT_DIR,STRINGS_FILE] stringByExpandingTildeInPath]];
however, the resulting path in the NSURL is:
file://localhost/Users/timothyborrowdale/SP2B/Localizable.strings
I have tried changing the PROJECT_DIR to
#"~/SP BB/"
#"~/SP\\\\ BB/" (changes to SP엀2B)
#"~/SP%20BB/"
#"~/SP\%20BB/"
with the same problem. I also tried typing out the file url completely and using [NSURL URLWithString:]
I have also tried using stringByAddingPercentEscapesUsingEncoding with both NSUTF8Encoding and NSASCCIEncoding and these have the same issue.
The NSString displays properly before being passed to NSURL or stringByAddingPercentEscapesUsingEncoding but has the problem once outputted from either.
Try this:
NSString *fnam = [#"Localizable" stringByAppendingPathExtension:#"strings"];
NSArray *parts = [NSArray arrayWithPathComponents:#"~", #"SP BB", fnam, (void *)nil];
NSString *path = [[NSString pathWithComponents:parts] stringByStandardizingPath];
NSURL *furl = [NSURL fileURLWithPath:path];
Foundation has a host of platform-independent, path-related methods. Prefer those over hard-coding path extension separators (often ".") and path component separators (often "/" or "\").
Try abandoning stringWithFormat: (never the right answer for stapling paths together) and stringByExpandingTildeInPath and using NSHomeDirectory() and stringByAppendingPathComponent: instead.
#"~/SP\\ BB/" (changes to SP엀2B)
How did you arrive at that conclusion?
Is there any easy way to set the contents of a webview to an HTML string (without having to load a file)?
Thanks
[[webView mainFrame] loadHTMLString:htmlString baseURL:someURL];
(Where someURL is used to resolve relative URLs in the HTML source.)
[webView loadHTMLString:yourString baseURL:[[NSBundle mainBundle] bundleURL]];
You can use [[NSBundle mainBundle] bundleURL] if you desire to load stylesheets(css) or javascripts(js) files that are in your resources dir, if not, just use nil
Yes definitely calling loadHTMLString:baseURL: on the mainFrame of the webView would do it.