Not able to display images in UIWebView from resource folder in iPhone SDK - iphone-sdk-3.0

In my project i want to display the Images in resources file in the webview
i am placing that content in html page and showing in web view.
in my body content having some images it is taking url like this
the problem is the image is not displaying in webview only question mark image is displaying in webview?
this is the code i written for this
NSURL *resourcePathURL = [[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] resourcePath] isDirectory:YES];
[self.webView loadHTMLString:contentString baseURL:resourcePathURL];
[resourcePathURL release];
i am taking image names like this "Asparagus-with-Shallots.png"
i am taking different dimenssion to each images 120*150,130*230 like this
'$''$'
'$'<p><img src=”Tiramisu.png”/><br>a computer file consisting solely '$'
'$' of printable characters from a recognized character set.4 servingsCream'$' '$'Filling1 cup mascarpone cheese (8 ounces) 1 a computer file consisting solely'$'
'$'of printable characters from a recognized character set! For the syrup:'$'
'$' '$'
I am attaching a image, I am getting the image displaying like in image getting from resource folder
Thanks

Just go through this post: iPhone Dev: UIWebView baseUrl to resources in Documents folder not App bundle. Looks like your question is answered here.

Related

How to fix "nsurlconnection finished with error - code 1100 " error for UIWebView in IOS?

I am working on an existing project where UIWebview is used to load html string to load js files for loading contents downloaded from our server.Currently UIWebview is not able to load the contents in IOS which is perfectly loading in Android.
I have tried to switch to WKWebView but still no luck.
self.webContentView.delegate = self;
NSString* html = [player getHTMLString];
NSString* baseURL = [player getBaseURLPath];
[self.pageLoadingActivity startAnimating];
[self.webContentView loadHTMLString:html baseURL: [NSURL URLWithString: baseURL]];
EDIT------
After debugging sometime I found I was getting two 1100 error.
It seemed like two file were missing or app was not able to read them.
Now whenever I am hitting shouldStartLoadWithRequest with
request
URL:
file:///Users/ealpha4tech/Library/Developer/CoreSimulator/Devices/2CA71983-9996-44D6-944F-34E3EAFAE96D/data/Containers/Data/Application/6A19ABBA-CB68-4EE4-AC02-6AD3CB8A5A68/Documents/icplayer/icplayer/D2D6AFFF93CB2CFCB1640484F5429D89.cache.html
I am getting 1100 error.(the above file is present though)
So as a guess, I would say [player getHTMLString] is the problem.
NSURLErrorFileDoesNotExist: The specified file doesn’t exist.
This is a local file error.
I'm guessing that -getHTMLString is trying to load a file out of the app, but that file is not being included in the app.
I could help more if you provide 2 things.
Provide the source for -getHTMLString
Use NSLog() to print value of [player getBaseURLPath].
UPDATE
In looking at your output, I noticed …ments/icplayer/icplayer/D2D6A…. I think the proper path should only have one icplayer not two. Look to see if it's getting repeated somehow.

What is the application Bundle and Resources folder

My question is about the application bundle in a project. I was reading about that and can understand some basic things (I'm not a native english speaker). I can understand that the resources folder is used to hold the files that will be used in the project, e.g. media files (images, audio, video, etc.) and should be in the application bundle to be identified.
So, what is the point if I want to use images and another resources in my project? In my other related question, I can't use them by referencing with NSImage imageNamed:.
I have used the following with no success loading my files:
NSBundle methods
imageNamed:#"string" with/without file extension
the images are in resources folder
I'm learning Cocoa and Objective-C, and of course this is different to C++ or Java when I want to create an ImageIcon or a QImage.
I may not have completely understood the issue, so correct me if I am wrong. I believe the problem has to do with your image's target membership or how you're retrieving the image in your code.
Adding an image to your project target will appropriately copy the resource at compile time. To add the image to your target, select it in the file navigator and then reveal the Utilities Panel. On the Utilities Panel, select the File Inspector Tab. Look for the Target Membership section and ensure that the image is selected for the desired targets:
Do you mean that you can't use the NSImage imageNamed: method to retrieve resources? If so, you can retrieve the resource like this (from the main resource bundle):
NSString *imageName = [[NSBundle mainBundle] pathForResource:#"image1" ofType:#"png"];
NSImage *imageObj = [[NSImage alloc] initWithContentsOfFile:imageName];
It also looks like you already have a good answer to your other related question.

Automatically selecting ipad #2x retina images for ipad3 from document folder

I am developing an iPad3/iPad2 application. In my bundle I have both iPad2 and #2xiPad3 images.It is working fine when i use bundle. In iPad2 low resolution images are detected and in iPad 3 high resolution ones are detected. But my problem is when I access it from document folder. How can i do the same for document folder. When I use document folder instead of bundle only low resolution images are loaded. Here is my code.
NSString *docsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES) objectAtIndex:0];
NSString *fileName = #"image.png";
NSString *path = [docsDirectory stringByAppendingPathComponentNSString stringWithFormat"/%#",fileName]];
I have placed image#2x~ipad.png also in the document directory. But it is not getting detected automatically in ipad3. I tried using image name without extension also. But the problem persist.
in side your document folder no need to set image#2x~ipad.png. just set image#2x.png is enough.

how to get the full path of an ios application? [duplicate]

I have a problem accessing my files in my app.
I am currently using
//Directly from TileMap example from WWDC2010
NSString *tileDirectory = [[[NSBundle mainBundle] resourcePath]
stringByAppendingPathComponent:#"Tiles"];
to access my tiles for my MKOverlay. This gives me this directory
/Users/xxxx/Library/Application Support/iPhone Simulator/4.2/Applications/9D62025C-C53B-472C-8309-xxxx/xxxx.app/Tiles
The x's is only for privacy reasons
I have my tiles in a folder called Tiles in the root of my application which is in Xcode in a group called Tiles which is in directly in the Resources group.
When I run my app, I get a simple error saying that it could not find my tiles at the generated directory (the one quote above) If I replace that piece of code and make it:
NSString *tileDirectory = #"/Users/xxxx/Documents/xxxx/Tiles";
Then my app works fine. This is obviously because it finds my tiles in its direct location on my Mac. This is fine for testing, but I need it to work on my iPhone/iPad.
This problem might be occurring due to:
The generated directory is incorrect.
The tile images aren't getting included in the builded .app file.
Either way, I have no clue of what to do to solve it.
How can I solve this problem?
[EDIT]
I changed that piece of code to:
NSString *tileDirectory = [[NSBundle mainBundle] resourcePath];
Now it works in simulator, because all files are in the apps root folder and I don't ask for it to enter another directory called "Tiles".
This runs with no error on the simulator, but when on my iPhone it gives the original error (just a different file path but also ending with /xxxx.app
How can I ensure a directory in my app file such as xxxx.app/Tiles - TileMap does this.
Since it is your files in your app bundle, I think you can use pathForResource:ofType: to get the full pathname of your file.
Here is an example:
NSString* filePath = [[NSBundle mainBundle] pathForResource:#"your_file_name"
ofType:#"the_file_extension"];
Remember that the "folders/groups" you make in xcode, those which are yellowish are not reflected as real folders in your iPhone app. They are just there to structure your XCode project. You can nest as many yellow group as you want and they still only serve the purpose of organizing code in XCode.
EDIT
Make a folder outside of XCode then drag it over, and select "Create folder references for any added folders" instead of "Create groups for any added folders" in the popup.
If your tiles are not in your bundle, either copied from the bundle or downloaded from the internet you can get the directory like this
NSString *documentdir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *tileDirectory = [documentdir stringByAppendingPathComponent:#"xxxx/Tiles"];
NSLog(#"Tile Directory: %#", tileDirectory);
You need to use the URL for the link, such as this:
NSURL *path = [[NSBundle mainBundle] URLForResource:#"imagename" withExtension:#"jpg"];
It will give you a proper URL ref.
You need to add your tiles into your resource bundle. I mean add all those files to your project make sure to copy all files to project directory option checked.

Saving Webarchive in Cocoa without images

I have a WebView that I want to save as a WebArchive. I just want to save the HTML part and not the referenced images. When I do the following, it appears to be creating a WebArchive with the images embedded as well.
[[[[[sourceSignatureWebView mainFrame] dataSource] webArchive] data]
writeToFile:#"MyWebarchive.webarchive" atomically:YES];
Besides the fact that I don't want to embed the images, Safari seems to have trouble displaying the file and is showing a lot of binary gibberish wrapped around the HTML part I want. I know I can use textutil to create the file, but if possible would like to do it all inside Cocoa.
Does anyone know if this is doable? Any ideas would be much appreciated. Thanks!
How about something like this:
WebDataSource *dataSource = [[sourceSignatureWebView mainFrame] dataSource];
WebArchive *archive = [[WebArchive alloc]
initWithMainResource:[dataSource mainResource]
subresources:nil
subframeArchives:nil];
[[archive data] writeToURL…
Or are you actually after an HTML file rather than web archive?