UIImageView + AFNetworking setImageWithURLRequest是否使用RestKit? [英] UIImageView+AFNetworking setImageWithURLRequest uses RestKit?

查看:91
本文介绍了UIImageView + AFNetworking setImageWithURLRequest是否使用RestKit?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将RestKit(0.20.0)用于我的Rest Api实现-所有GET,POST等。这些GET返回图像的一些URL。我正在使用UIImageView + AFNetworking setImageWithURLRequest函数下载这些。看到RestKit日志为这些获取而打印时,我感到很惊讶,因此我进行了一些调试。看来AFNetworking发送了一些通知,这些通知最终落在了RestKit上。

I am using RestKit (0.20.0) for my Rest Api implementation - all the GETs, POSTs etc. The GETs return some urls for the images. I am using UIImageView+AFNetworking setImageWithURLRequest function to download these. I was surprised to see RestKit logs getting printed for these fetches so I did some debugging. It seems that some notification is sent by AFNetworking that eventually lands on RestKit.

看起来很像是因为AFNetworkingOperationDidStartNotification被触发以获取图像,并且RK已在RKObjectRequestOperation.m中为此通知注册了它。 。

Looks like its happening because AFNetworkingOperationDidStartNotification is fired for the fetch of the image and RK has registered for this notification in RKObjectRequestOperation.m.

        [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(HTTPOperationDidStart:)
                                                 name:AFNetworkingOperationDidStartNotification
                                               object:nil];

我的问题是-


  1. 考虑到我使用此api的目的是要确保图像获取与RK完全独立/互斥,对我来说应该由谁来路由呢?

  1. Should it matter to me who is routing this given that my thinking behind using this api was to ensure that the image fetches are in completely separate/exclusive threads than RK.

这会影响我的CoreData实现吗?该图像是否会被缓存-我猜不会,因为我没有明确存储它,但是如果这些操作开始与Rest api操作在同一池中发生,它是否可能影响性能?

Does this impact my CoreData implementation? Will this image get cached - I am guessing it wont be because I am not explicitly storing it but can it possibly impact performance if these operations start to happen on the same pool as the Rest api operations?

这是正确的实现吗?我是否应该在CoreData中也缓存图像,而根本不使用AFNetworking api?

Is this the right implementation? Should I cache the images as well in CoreData and not use AFNetworking api at all?

稍有不同,但相关的主题-我计划从中获取数百个项目服务器中,每个项目也可以有很多项目。并且每个都将有图像。因此,它是一个相当庞大的网络繁重的应用程序。是否有任何最佳实践来管理这些请求的节流以避免性能下降?

Slightly off but related topic - I plan on getting hundreds of items from the server, each of these items can have many items as well. and each of these will have images as well. So its a pretty network heavy application. Are there any best practices to manage throttling of these requests to avoid performance hiccups?

Thx提前寻求帮助。

Thx in advance for the help..

推荐答案


考虑到我使用此api的想法,谁来路由这对我来说很重要是为了确保图像获取是在与RK完全不同的/排他的线程中进行的。

Should it matter to me who is routing this given that my thinking behind using this api was to ensure that the image fetches are in completely separate/exclusive threads than RK.

不,它不应该。该请求仍将在其他线程上运行。

No, it shouldn't. The request will still run on a different thread.


这会影响我的CoreData实现吗?该图像是否会被缓存-我猜不会,因为我没有显式存储它,但是如果这些操作开始与Rest api操作在同一池中发生,它是否可能影响性能?

Does this impact my CoreData implementation? Will this image get cached - I am guessing it wont be because I am not explicitly storing it but can it possibly impact performance if these operations start to happen on the same pool as the Rest api operations?

图像将仅缓存在内存中(如果有可用内存)。通常,我同意@ m-farhan的观点, SDWebImage 是一个更好的选择,不要与Core Data分开,而是将图像缓存到磁盘,这样就不必继续下载它们了。 。通常,您不想将图像存储在Core Data中。

The image will only be cached in memory (if memory is available). Generally I agree with @m-farhan that SDWebImage would be a better choice, not to separate from Core Data but to cache the images to disk so you don't keep downloading them. Generally you don't want to store the images in Core Data.

如果同时进行所有请求,那么任何请求都会影响性能。您应该将并发网络操作限制为〜4或5。

Any requests can impact performance if you make them all at the same time. You should limit your concurrent network operations to ~ 4 or 5.


这是正确的实现吗?我应该在CoreData中也缓存图像,而根本不使用AFNetworking api吗?

Is this the right implementation? Should I cache the images as well in CoreData and not use AFNetworking api at all?

请参见上文。


略有关系,但相关的话题-我计划从服务器上获取数百个项目,每个项目也可以包含许多项目。并且每个都将有图像。因此,它是一个相当庞大的网络繁重的应用程序。是否有任何最佳实践来管理这些请求的节流以避免性能故障?

Slightly off but related topic - I plan on getting hundreds of items from the server, each of these items can have many items as well. and each of these will have images as well. So its a pretty network heavy application. Are there any best practices to manage throttling of these requests to avoid performance hiccups?

请参见上文。在 RKObjectManager operationQueue 上设置并发计数。

See above. Set the concurrent count on the operationQueue of the RKObjectManager.

这篇关于UIImageView + AFNetworking setImageWithURLRequest是否使用RestKit?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆