I want to make a hybrid app , because some files(like images) have been cached in my app's bundle already. If I use a webView to load a web page in server. and this webPage is use these images , can the webView to visit the app's bundle file system?
You could use some custom links to refer your bundle and change it on the fly from your app.
Let's say you use bundle://image.png then in your code you replace all "bundle://image.png" strings with someting like
[[NSBundle mainBundle] pathForResource:#"image" ofType:#"pnf" inDirectory:#"html_files"];
Anyway this approach creates a strong interdependence into the server and the app wich is not good I think.
I will use a more conventional approach caching images with something like: https://github.com/path/FastImageCache
Related
I am developing an iOS app that uses a large amount of images that are needed for animations for short videos. I want to save my application assets as static files in cloud and once they are needed download them using secure API call (either JSON, XML or any other alternative for that matter).
What is the best option for that. I have checked Parse, Dropbox, iCloud, Google Drive, but I am puzzled since I see only instructions for dynamic data that lets users access content they have created and not static assets.
What would be best option for that?
If you just want an easy way to serve static files I would take a look at Amazon S3. You can just upload files through the online console and then get the public URL to those files to use in your app. You can also use the S3 API to upload files through your web service or iOS app.
Hope this helps!
I'd go for Parse (basically because it is fast to learn and develop), you can create a table with the images and change the writing permissions if you are afraid somebody could modify the table.
Another option that you can check it's the special Config table so you can upload custom files (zip files i.e.) and download them in demand.
Well, i searched everywhere but i didn't have any luck with my situation.
I am loading my webpage with UIWebView with the following code:
NSString *fullURL;
fullURL=#"http://domain.com";
NSURL *url=[NSURL URLWithString:fullURL];
NSURLRequest *requestObj=[NSURLRequest requestWithURL:url];
[_webView loadRequest:requestObj];
I want to load the remote HTML file but load the images from the bundle resourses.
The HTML file looks like this:
<img src="http://domain.com/images/image.png" width="20px" height="20px"/>
Can this be done? The majority of the posts over the internet(and here) are for loading local HTML with local images/resources which is different in my case.
Any help with my code?
Thanks
It would probably be better to use some more "loosely coupled" solution - not to edit the HTML code itself in some hacky way (regexp, not regexp... changing the HTML code manually is still pretty hacky).
As a matter of fact, I believe it can be done. The iOS just needs to be somehow informed that some of the assets are available offline, from the bundle.
Basically, when UIWebView is loading a page, first thing that happens behind the scene is downloading the main *.html page. Then all the graphics/css'es/js'es etc are being downloaded.
You can let the html file be downloaded "as is", but intercept those requests that are going to download graphics (+ other assets) and provide them from local bundle. Please refer to this post:
http://robnapier.net/blog/offline-uiwebview-nsurlprotocol-588
and apply appropriate changes. The big win here is that from the webview's (and code that loads / maintain via JavaScript calls it's content) perspective - nothing has changed at all. Only the custom NSURLProtocol itself knows that some data was loaded from local storage.
Had the exact same problem. Subclassing NSURLCache to redirect the cache to cache images from local storage worked like a charm.
Here is the writeup that I followed:
http://www.cocoawithlove.com/2010/09/substituting-local-data-for-remote.html
TL;DR Complicated, avoid if you can, but possible.
If you still want to do it: don't do a UIWebView :loadRequest on the URL itself since it will trigger the start of downloading images very rapidly so modifying the images sources using Javascript will likely happen too late.
What you instead have would have to do is to download the contents of the URL on the native side and iterate the image tags there replacing the sources (quite complicated, don't use Regular Expressions to parse HTML btw, there are libraries for that), then injecting the modified HTML using UIWebView loadHTMLString:baseURL:.
I have a question regarding how to update local images embedded as content in the application.
My application is built using 30 images stored as "Content" (embedded in the app) for a image gallery that I have to show. Every 2 days the application check server info to see if the images have been changed in the database, in that case then I have to compare files and if any file has changed then I have to download it and update the local image.
I have read the the best way to store images for this kind of porposses is under "Library" folder of the application, but the images that comes with the app are built as "Content" (embedded)...
Any clue on the best way to do that in monotouch?
Thanks.
Resources, like images, that you bundle inside your .app becomes part of your application. Since the application is signed you cannot update (or remove) those files as it would invalidate the signature (there's also file permissions that won't allow this to happen).
note: it can work in the iOS simulator since it does not require (or check) for application signatures, however it won't works for application on devices.
What you can do is:
Bundle default images with your applications;
Download new images (when needed) and install them outside your application (in the appropriate directory);
Have your application checks if there are downloaded images (or if images needs to be downloaded) and fallback to the images that ships with your application;
You can't change any file from your app (they're read-only).
What you can do is to save the files to a read-write directory, and at runtime check if those images are there (and not then use the ones bundled with the app).
I'm absolutely new to iOS App development (I haven't actually started yet, still in a design phase).
The task that I have to accomplish with my app is to download a zip from somewhere, extract anywere to local storage and display its content (html pages with javascript) in a embed webkit widget.
The questions are:
1) Will my app have access to any folder of my iPad storage memory?
2) Will my app's embedded Webkit widget be able to display local html pages (like file:///somewhere/over/the/rainbow.html ?
3) WIll that local page be able to use Ajax method (over httpxmlrequest) to dynamically load external scripts or xml (also locally stored - ie ./something.xml)?
Thank in advance for any help!
No it can't access any file. Apps are sandboxed on iOS. You can only access the app bundle's content and documents folder (a writable area unique to your app).
Yes - provided said content is in the areas mentioned in (1). This is how Phonegap-based apps work.
Yes - they can. We've done exactly this extensively in several of our apps.
I am making an iPad application (iOS 5.0/5.1 with ARC and storyboard) for which I need to download an image or sound file from my server and then use it as background for all the screens of my application. I was thinking of keeping a placeholder image/audio file bundled within my application which I will refer to within the storyboard. Then when I get the file from the server, I can replace that image with the one coming from the server. However, I'm not sure if this can be done based on the directories that the app has access to.
Pls let me know if you can direct me whether it's possible to go down this road? and if yes, then which directory should I be downloading the image files to?
Thanks in advance for your help