2012-08-13 39 views
0

我目前正在使用MKNetworkKit缓存来自宁静服务器的多个图像的下载。我还有另一项宁静的服务,可以获取关于图像的补充信息。无论服务器我先PING工作,但查验第二个服务器我收到以下错误时:如何拥有MKNetworkKit的多个子类?

[The operation couldn’t be completed. (NSURLErrorDomain error 404.)] 2012-08-12 19:51:12.340 [51853:11603]

Error: Error Domain=NSURLErrorDomain Code=404 "The operation couldn’t be completed. (NSURLErrorDomain error 404.)" UserInfo=0x73c5490 {Server=Apache-Coyote/1.1, Content-Length=47, Content-Type=text/html;charset=ISO-8859-1, Connection=keep-alive, Date=Sun, 12 Aug 2012 23:51:11 GMT} 2012-08-12 19:51:12.341 [MKNetworkOperation operationFailedWithError:] [Line 1280] State: 0

MKNetworkKit在强制的第一台服务器在尝试从第二个服务器的URL获取数据。我想我可能需要创建另一个可达性对象?任何想法我做错了什么?或者我可以在其中找到一个具有多个子类的项目的示例实现?

编辑 我实现这两个引擎的方式如下:

@implementation FirstEngine 

FirstEngine* _sharedEngine; 

+(FirstEngine*)sharedEngine 
{ 
    if(_sharedEngine==nil) 
    { 
     _sharedEngine = [[FirstEngine alloc] initWithHostName:@"***.**.**.**" customHeaderFields:nil];    
    } 
    return _sharedEngine; 
} 

,并调用它们是这样的:

$[[FirstEngine sharedEngine] bodyForPath:url verb:verb body:params onCompletion:^(NSDictionary* body) 
{}.... 

$[[SecondEngine sharedEngine] bodyForPath:url verb:verb body:params onCompletion:^(NSDictionary* body) 
{}.... 

回答

1

您应该创建一个MKNetworkEngine对象在你的AppDelega中对于与您交谈的“每个”服务器。

self.imageCacheEngine = [[MKNetworkEngine alloc] initWithHostName:@"images.myserver.com"]; 

self.apiEngine = [[MKNetworkEngine alloc] initWithHostName:@"api.myserver.com"]; 

排队图像请求到imageCacheEngine和API请求您apiEngine。

+0

感谢您的回复。考虑到上面的代码编辑,我该如何做到这一点? – 2012-08-15 18:38:34

+0

您不应该重写sharedEngine。在AppDelegate中创建引擎后,使用[AppDelegate.engine imageAtURL ...] – Mugunth 2012-08-17 03:53:44

相关问题