iOS - Caching and loading images asynchronously - iphone

I want an image loading and caching library for iOS that
loads images asynchronously,
caches images, with a configurable cache size and LRU behaviour,
checks to see if images have been updated, using HTTP HEAD,
doesn't cache anything in the event of an error code or an invalid image.
I've looked at HJCache, but it only satisfies the first two of these criteria. Is there something better?

I know that this thread has been answered, but I have tried a library that has worked great. I was using ASIHttpRequest before and the difference is big.
https://github.com/rs/SDWebImage
Also, if someone needs to Resize or Crop the remote images, and have the same features that SDWebImage provide, I have integrated SDWebImage library with UIImage+Resize library (by Trevor Harmon), and created an example project. I modified the code of SDWebImage to deal with transformations (crop, resize).
The project is public on https://github.com/toptierlabs/ImageCacheResize. Feel free to use it!

EDIT : ASI has been deprecated now but #Tony's answer has a link to a library that seems to do most of this (disclaimer - I've not yet tried it and am going by #Tony's recommendation!)
ASIHTTPRequest does all of that :)
All you would have to do is add something like to the success callback
UIImage *image = [UIImage imageWithData:[request responseData]];
// If the image is nil ASIHTTPRequest will let you remove the data from the cache
// but I can't remember off the top of my head how. Checkout the docs!
EDIT
And when you've finished it, you could always pop it onto github for the rest of us . . .

I had a look recently for the sort of thing you describe -- either a general data cache, or an image centric one -- and didn't find much of interest. So you may have to roll your own to get all those features.
There's a various blogs posts and things detailing such things, such as
http://davidgolightly.blogspot.com/2009/02/asynchronous-image-caching-with-iphone.html.
I take it you've considered the Three20 library? I don't think it would cover your requirements though.

Related

reuse result of initialize method from video_player flutter package

Is there option to reuse result of initialize method for video_player package? It takes time for complete - it would be great to cache it (eg. memory level) and reuse it when you back to before used video - and simple use cached data instead of wait for initialize result. I need it for intensive switching between videos.
There is a package called cached_video_player which may help resolve your problem. Check it out here.
I think you are asking about having the screen/page/widget pre-render. That is not currently supported by flutter according to this issue filed on github:
https://github.com/flutter/uxr/issues/6#issuecomment-881918751
Sure, but this is not very scalable and will quickly turn into a mess. It's much simpler and more flexible to just give MyRoute someway it can cache the next route, and then show that cached route when it needs. But flutter doesn't support this as everything needs to be 'on-stage' before it can be initialized. In AIR, or Unity, I could simply construct my new page, and it would begin loading data, I could then toss it on stage whenever I want.
PS. You probably already know you can pre-cache the video data/file itself.

How to clear/invalidate ambient cache on iOS app

When I update tilesets on mapbox, changes don't appear in the iOS app unless I re-install it. There is seemingly documentation on this here: https://docs.mapbox.com/ios/api/maps/5.2.0/Classes/MGLOfflineStorage.html#/c:objc(cs)MGLOfflineStorage(im)setMaximumAmbientCacheSize:withCompletionHandler: but I can't figure out how exactly to implement it. I don't have an MGLOfflineStorage object because I am not worried about offline map storage right now, I just want to refresh the cache in the app. There are good examples of how to do this in android, but not on iOS. Any help is appreciated (preferably in swift)
It appears to be correct to call the methods on the shared MGLOfflineStorage object. The method parameter should be a closure containing any code you want to execute upon completion.
MGLOfflineStorage.shared.invalidateAmbientCache { error in
print("Invalidated")
}
Naturally you should check the error in the usual 'safe' way.

How to get frame data in AppRTC iOS app for video modifications?

I am currently trying to make some modifications to the incoming WebRTC video stream in the AppRTC app for iOS in Swift (which in turn is based on this Objective-C version). To do so, I need access to the data which is stored in the frame objects of class RTCI420Frame (which is a basic class for the Objective-C implementation of libWebRTC). In particular, I need an array of bytes: [UInt8] and Size of the frames. This data is to be used for further processing & addition of some filters.
The problem is, all the operations on RTCVideoTrack / RTCEAGLVideoView are done under the hood of pre-compiled libWebRTC.a, it is compiled from the official WebRTC repository linked above and it's fairly complicated to get a custom build of it, so I'd prefer to go with the build available in the example iOS project; in my understanding it's supposed to have all the available functionality in it.
I was looking into RTCVideoChatViewController class and in particular, remoteView / remoteVideoTrack, but had no success in accessing the frames themselves, spent a lot of time researching the libWebRTC sources in official repo but still can't wrap my head around the problem of accessing the frames data for own manipulations with it. Would be glad for any help!
Just after posting the question I had a luck in finding the sneaky data!
You have to add the following property to RTCEAGLVideoView.h file:
#property(atomic, strong) RTCI420Frame* i420Frame;
In the original implementation file there is the i420Frame property but it wasn't exposed in the iOS project's header file for the class. Adding the property allows you to get view's current frame.
I'm still in search of a more elegant way of getting the stream data directly, without the need to look into remoteView contents, will update the answer once I find it.

How to render SVG images in iphone without uiwebview?

I want to render SVG images in iPhone without using a UIWebView. How can I do that?
I have checked these 2 links:
http://www.splashdust.net/2010/09/svgquartzrenderer-a-basic-iphone-sdk-compatible-svg-renderer/
https://github.com/splashdust/SVGQuartzRenderer
The above project on Github shows 102 errors showing UIKit framework missing and others and I are also not able to add that framework.
I think the application is for MacOS not for iOS.
http://maniacdev.com/2011/05/open-source-library-to-render-svg-graphics-as-core-animation-layers/
https://github.com/mattrajca/SVGKit
The project on the above url shows the error when i build the project.
Target specifies product type 'com.apple.product-type.framework', but there's no such product type for the 'iPhoneOS' platform.
Does anyone know how to solve that? Or other useful working examples that I can use for that? I want to render SVG's on iPhone.
UPDATE: I have got working SVGKit working by reading instructions. But when I tried to make project working which iI downloaded from Github (https://github.com/splashdust/SVGQuartzRenderer
) I got following errors:
1) UIKit/UIKit.h: No such file or directory (I am not able to add it using add existing framework)
2) Libxml/tree.h: No such file or directory
3) Expected specifier-qualifier-listbefore 'xmlParserCtxtPtr'.
Does anyone know that how to resolve it and make it work?
Jason Morrissey, author of the extremely excellent Alien Blue app, the best iOS Reddit client on the store (can you tell I'm a fan? I'm also a beta tester.) recently put up his SVGKit framework, which renders SVG images as Core Animation layers. I haven't used it, but I know it exists.
And then, look... if you're just getting lots of errors when you bring in other people's classes, my strong suspicion is that you're not following their "how to use" instructions. They'll mostly tell you what frameworks are required and what platforms they support. Every time I've tried to use something like this and had a compilation bloodbath, I've gone back and found some installation instruction step I missed.
I just managed to compile SVGFlashRenderer.
For iOS you need to open the project from the directory SVGRendererTouch.
And don't forget to separately download contents of the lib/MROGeometry dir from github (just follow the link in the source tree).
P.S. For me, the best working solution was SVGKit, but not the version from Jason Morissey (mentioned in another answer), but a fork from reklis. It has many bugs fixed and works in a much more correct way.
It's easy.
SVGKImage *svgImg = [SVGKImage imageNamed:#"add-control-panel"];
SVGKFastImageView *imgView = [[SVGKFastImageView alloc] initWithFrame:CGRectMake(10, 100, 420, 280)];
imgView.image = svgImg;
[self.view addSubview:imgView];

How to empty cache for WebView?

I have a Webview that must load an image! When I upload this image I see every time the same image as before, and i must reboot my app to see the new image...
I think is a cache problem..How can I solve that??
One quick and easy method would be to append the current time stamp onto the url whenever you load it.
So instead of loading:
http://www.myhost.com/myimg.jpg
you'd load
http://www.myhost.com/myimg.jpg?12345689
Using a cache breaker like this is a very common method in web development to force reloading of content.
I did do some quick googling and it appears clearing out NSURL's cache won't do the trick. In 10.6 the api reloadFromOrigin: may do the trick, but I'm not aware if this has made it's way onto the iphone yet.
Edit:
I found this page in the docs. It looks like you can use the preferences system to say whether or not to use caching. Not tested, but that'd be something to look at.