NSData +dataWithContentsOfURL has any kind of caching by default? Has anyone experimented some kind of problems using this method, what is the most efficient way to get Data from the web?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- how do you prevent page scroll in textarea on mobi
- Custom UITableview cell accessibility not working
相关文章
- Could I create “Call” button in HTML 5 IPhone appl
- Unable to process app at this time due to a genera
- How do you detect key up / key down events from a
- “Storyboard.storyboard” could not be opened
- Is there a google API to read cached content? [clo
- Open iOS 11 Files app via URL Scheme or some other
- Can keyboard of type UIKeyboardTypeNamePhonePad be
- Can not export audiofiles via “open in:” from Voic
It seems that on iPhone5s the default policy is to cache (unlinke iPhone5 and earlier).
You can handle via the options parameter the cache policy for NSData . For example,if you want to avoid cache, the following snipped can be used :
The documentation doesn't say that it will cache, so I think we should assume that they don't do any caching.
Which kinds of data you want to get
UIImage : yes, I think you should use NSData
Video: you should use MPMoviePlayerController for streaming
Text: I think you can do normal NSUrlConnection. It also has asynchronous, synchrnous and caching
Use ASIHTTPRequest. It's a third party HTTP client library that makes network interaction MUCH simpler, and has very nice caching functions.
UPDATE: Just got a downvote on this answer, which is a good reminder to come back and update. Lot has changed since August '10. Most notably: ASIHTTPRequest is now deprecated, and its author is encouraging people to use something else. AFNetworking seems a popular choice.
if what you need is just downloading image from a url, don't bother to use any libraries, just a simple dispatch_async call should be OK. like this:
It's best to use NSURLConnection. The NSURLRequest you give it can be configured to do the caching the way you want but by default it will just do standard caching of HTTP resources that have the appropriate headers in their response.
This is what I do:
Make sure to put this in an NSOperationQueue that isn't your main queue or off-load it from the main thread in some other way, though. Alternatively, use an asynchronous request.