ios - Am I using correctly the requestImageForRequest at DFImageManager? -
i'm using lib called dfimagemanager
, , i'm not quite sure i'm going right way.
i led believe within completion block of requestimageforrequest
info
can used detect if request success.
however, 10% of time info
nil
image
has value.
what info
param for? when info
nil
, can still use value of image
?
dfimagerequestoptions *options = [[dfimagerequestoptions alloc] init]; options.expirationage = 60; dfimagerequest *request = [dfimagerequest requestwithresource:[nsurl urlwithstring:imageurl] targetsize:imageview.frame.size contentmode:dfimagecontentmodeaspectfill options:options]; [[dfimagemanager sharedmanager] requestimageforrequest:request completion:^(uiimage *image, nsdictionary *info) { if (info != nil) { [imageview setimage:image]; } else { // use placeholder } }];
completion block guaranteed called on main thread. completion block called synchronously when requested image can retrieved memory cache , request made on main thread.
this case when info
nil
. implementation similar phimagemanager
, calls completion blocks synchronously (instead of asynchronously) based on request. necessary reload ui without worrying drawing frames empty image views, when images available in memory cache. , single requestimageforrequest
method keeps memory caching transparent client.
what info param for?
if holds error when there 1 (see dfimageinfoerrorkey
key). , requestid (dfimageinforequestidkey
). info nil, when request handled memory cache.
when info nil, can still use value of image?
yes, can. should check if image not nil instead of checking info:
if (image != nil) { [imageview setimage:image]; } else { // use placeholder nserror *error = info[dfimageinfoerrorkey]; // handle specific error (if there one) }
i'm going make things more obvious nullability in next release:
- the
requestid
shouldnonnull
.info
shouldnonnull
(even when request can handled memory cache) , should containrequestid
. - the
request
,resource
should bothnonnull
. - image manager should raise exception when request invalid (unsupported asset).
Comments
Post a Comment