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 :)
Related
I was doing web scraper but then I got blocked for too much commands and someone said I should retriev the json itself with this url and try play with it :https://steamcommunity.com/market/search/render/?query=&start=1490&count=10&search_descriptions=0&sort_column=price&sort_dir=desc&appid=730&norender=1
and I changed it to this :https://steamcommunity.com/market/search/render/?query=&start=0&count=100&search_descriptions=0&appid=730&norender=1 but when I try to do more than 100 it doesn't give me more outputs is there a way to fix this? Btw Iam new to programing and stuff, so I dont know much.
Short answer: no.
These query parameters are most likely limited by Valve itself. Also, WebScraping / Crawling has the huge disadvantage that many or even most providers are actually blocking requests after a determined amount of requests / after a distinct use pattern whatsoever.
The only way to counteract this is to use an official API. By now, there's no such thing though.
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.
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.
I'm developing a game where the main element of gameplay is an image of 2400x1600 pixels. So we are having some discussion about what's the best approach we could follow and confirm that we are not missing anything in order to download the image from the server and get it displayed on the device. So we thought about the different approaches and see what everyone else's thoughts are. I would really appreciate if you can list another approach you can think of. Before getting into the approaches themselves, some things that we need to take for granted:
User experience since gameplay started should be smooth. This made us get rid of one possible approach that was to implement it like Google Maps i.e. downloading tiles from the server as the user pans/zooms the map since there will be for sure some delay until the tile is finally displayed.
Images cannot be shipped within the binary file since they will be updated frequently.
All the tiles of each image weight around 6MB
So possible solutions we see so far:
Download and tiling the images in a background process/task all at once as they get updated. The big loading time here will be the first time the user launches the app. Images don't get updated together neither very frequently - one day minimum.
From the moment the user gets to the screen to select the image to play, start the process of downloading and tiling. User can select between 2 pictures only.
If user is on WiFi, use solution 1. If user is over cellular network then use solution 2.
Thanks in advance.
Use SDWebImage. It provides a ton of features for caching images, downloading in background, and much more.
The NSURLSession class in iOS 7 is well-suited for your needs. It allows for background downloads, resuming and pausing downloads, and is heavily customisable.
Now, I know this is a little vague, so here are some great references to start with :
Apple's NSURLSession Documentation
Mobile.TutsPlus NSURLSession Tutorials
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.