How to share images cache between WKWebView and the rest app - ios

I'm working on a news aggregation project like Flipboard. And lots of the images are the same in UITableView feed list and corresponding content rendered by WKWebView. It would save significant web traffic if a share cache exists.
Is it possible? Thanks in advance for your response.

Simple answer, at the moment this is not possible. You could think of a way to actually display the images in a WKWebView, but that might be, depending on your use case, quite impractical.

Related

Downloading and using a large number of avatars

I'm wondering if you can help me solve more of a general, process question.
In my app when the user signs up, I create a thumbnail avatar (approx 35x35 px). I upload this to the server.
In another section of my app I display all users in a UITableView. This table is populated by a request that occurs on the view controller beforehand (so I can reduce loading screens).
This table contains approximately 100 rows. My question is, how do I load all the avatars seamlessly?
I dont want the user to tap the view and see a bunch of users, then avatars loading in randomly.
I dont want a loading screen to appear, unless its absolutely necessary (i.e. the user navigates through the app quickly).
I dont want to fire off 100 requests at once to my server.
I would like to send one request, and possibly get them back all at once. And if I did this, is there a specific format I should use? A big JSON response with base64 encoded thumbnails? :/
In addition to this, should I cache these? If so, how?
Swift 3.
Thanks!
SDWebImage is a really amazing framework that you can use to achieve this task. I've used it in every app of mine.
You can find it here: https://github.com/rs/SDWebImage
You can just put the following code in your cellForRowAtIndexPath Method
cell.imageView.sd_setImageWithURL(String.initWithURL("http://www.domain.com/path/to/image.jpg"))
The URL specified here is the link to the individual image to be shown in that particular row. This way your app can load images as the user scrolls the tableview. Given that your images are 35x35, it should be smooth and quick.
Hope this helped!
After more research based on Pratham Mehta's answer, I found a library called KingFisher:
https://github.com/onevcat/Kingfisher
This is more appropriate for my project, given SDWebImage is written in Objective-C, and my project is in Swift 3.
Check out Nuke. It's designed to support large collections of images (has built-in throttling, rate limiting of requests, etc).
And if I did this, is there a specific format I should use? A big JSON response with base64 encoded thumbnails? :/
I would suggest to avoid any premature optimizations - just download the images lazily one by one as soon as they appear on the display. Most image loading frameworks are designed to support this really well.
In addition you can prefetch the images.
If you want to do it the hard way - just zip the images and download the archive.
In addition to this, should I cache these? If so, how?
You may find this helpful.

xcode/ios/json api: Is it best practice to use pagination when pulling in json feed?

IOS newb working on app that pulls JSON feed from web server into an IOS app.
Is it best practice to create an API (in PHP in my case) that spills all the records--which could be thousands into a JSON feed and have the IOS app handle all of them (though displaying only one screen at a time)?
Or is best practice to limit the results in the JSON feed to say ten or one hundred and then have some user action in the IOS App draw down the next batch?
The first would seem more desirable given the reusable cell concept, however, it seems that sending huge numbers of records is bound to be slower and/or problematic from a web traffic and memory management point of view.
On the other hand, the second seems really complicated. How would you know which page to pull down based on IOS style gestures.
Looking to learn best practice on this as it seems to be common for many apps.
Many thanks for any suggestions.
It probably depends on your use case. If you have a lot of data then you probably wouldn't want to load all of them at once. At a certain point it will take too much time and you probably have to do that more than once if you don't persist or if you want to refresh.
In that case a good API is designed to be iterated over e.g. limit/offset parameters. Meaning for example the user scrolls a list of items and when scrolling to the bottom of the list you fetch a new batch of items.
In the other case where one call is fast enough to deliver all the data at once there is no reason to make it more complicated as you said and you can still add iteration afterwards.

asynchronous request of images by url for scrollview ios

I wanted to know how it is possible to make asynchronous request of images, and display them in a scroll view in a way that I can scroll the images without making requests for each images. I read some threads that gave me some ideas, so I think that I have to stock the urls in an array, and then I don't know what to do. If someone can explain to me ? or have a concrete idea on how to do this ?
NSScreencast has a video that does something similar. It is also a good video to learn about blocks too.
http://nsscreencast.com/episodes/10-fun-with-blocks
in order to load images asynchronously there are many options. The best approach is to create a different thread and fetch the url.
Sometimes its better to used tested and trusted apis available. I will suggest you to use SDWebImage
This will not only help you to load images asynchronously but also provides the caching mechanism. Which you will later or sooner user in you app development.
Its easy to use. Happy Coding :)

Displaying images in an iOS web view through a URL in an sqlite database

I am very new to sqlite and I need help. I have looked a lot on the net, in books and within Stack Overflow for a solution to my problem, but so far no cigar.
I have some text saved in an Sqlite database that I display in a webview and I would like to add a photo once every 50 lines of so. The photos themselves would reside in a server. According to tutorials I found on the net, regular HTML like
<img src="http://rempu.modwest.com/photo/SS.png" alt="some_text">
embedded in the text should work in sqlite but I get only the missing image icon. The fact the icon appears at all seems to indicate that the HTML is understood and the problem is the URL. I have tried relative URLs with local files, absolute ones with remote files but nothing works even with paths I know to be correct.
.
Lots of Stack Overload pages suggest to use URLs rather than BLOBS for images in sqlite, none I found explains HOW this is done. Anybody can help? I apologise in advance if my question is dumb.
Thanks,
Frank
So your question isn't dumb, but it is a little confusing. If I understand it correctly, you're trying to display images with some alt text inside a UIWebView?
So most of what you're probably going to see here on SO related to images & iOS is downloading those images to display natively inside something like a UITableView or something like that. That's probably just going to confuse the issue here.
What I would do is, inside the SQLite database, store absolute URLs (include the http:// and FDQN) for the images you want to display. Then, when you're building the HTML (which it sounds like you're then displaying using UIWebView's loadHTMLString:baseURL:) just insert those URLs into the appropriate HTML tags. You can then shove that string into loadHTMLString and UIWebView should take care of loading the approriate images for you!
And yes I completely agree with whoever told you BLOBs are a Bad Thing™ in SQLite. However, I've seen some "clever" solutions with utilizing base64 encoding of images and storing the resulting string in a TEXT field in SQLite. This is slightly better but not by much. It's an option though if you want, and you'll just need to go get the appropriate HTML code to load a base64 image source.
Let me know if that works!

Instagram MIN_TIMESTAMP not returning all images it should

I'm developing an iOS app and my idea is to display all Instagram images after a certain timestamp. I use HSInstagram to handle the API response and put all the images in a UIScrolView.
In order to do so, I do a request to the following path: users/%#/media/recent/?acces_token=MY_ACCESS_TOKEN&min_timestamp=1350000000. But the response I get is just a limited number of images, which aren't all the images after my timestamp.
I thought it was due to the limit that instagram puts on 20 images every request and thus I also tried to do the request to users/%#/media/recent/?acces_token=MY_ACCESS_TOKEN&min_timestamp=1350000000&count=-1 to avoid the limit. But in this case, the images didn't even load.
I'd appreciate any contribution. Thanks for your time!
As HSInstagram code was not prepared to implement the feature I wanted to implement, I foud an alternative called GrabKit in which you can also import your Facebook and Picasa images among others although you can disable them if you want to.
I hope this library can help you if you want to build an application that supports Instagram pictures the same way the app I'm building does. I really recommend it if you want to save thousands of lines of code as well as many hours dealing with APIs.

Resources