我对Objective-C和XCode相当新,但是甚至比RestKit更新,尽管已经用Java编程了12年。
我有一个连接到RestKit的IOS应用程序,并且从静止服务器加载的操作仅在第一次工作,如果我返回导航控制器并再次尝试相同的操作,则调用loadObjectsAtResourcePath:delegate
方法,但是没有一个委托方法被调用(我实现所有这些只是为了记录它们发生时)。
我觉得我已经错过了Restkit的基本功能,也许是它的异步性质,因为第一次映射显然工作正常,因此后续调用必须在异步队列中丢失。
我用谷歌搜索了这个,看到类似的人被类似的东西卡住了,但是尝试了所有这些并且似乎没有什么区别。缓存被禁用,objectLoaderDidLoadUnexpectedResponse
和didFailWithError
永远不会被调用,它会被放到场内。
代码来源:
我的XCode项目已在github上发布here
执行加载调用的特定View Controller是here(请参阅setUpRestKit方法)
调用顺序如下:
启用日志,这是我看到的模式,第一个调用完成时注释,第二个调用开始时等(为了清晰起见,时间戳被修剪):
ElasticSearchHeadIOS[25064:fb03] I restkit:RKLog.m:32 RestKit initialized...
ElasticSearchHeadIOS[25064:fb03] I restkit.support:RKCache.m:178 Invalidating cache at path: /Users/paulsmith/Library/Application Support/iPhone Simulator/5.1/Applications/BDB8B59F-8307-4F18-A4E7-C55849618D77/Library/Caches/RKClientRequestCache-localhost/SessionStore
ElasticSearchHeadIOS[25064:fb03] I restkit.network.reachability:RKReachabilityObserver.m:155 Reachability observer initialized with hostname localhost
ElasticSearchHeadIOS[25064:fb03] D restkit.network:RKClient.m:271 Reachability observer changed for client <RKClient: 0x80756e0>, suspending queue <RKRequestQueue: 0x8082600 name=(null) suspended=YES requestCount=0 loadingCount=0/5> until reachability to host 'localhost' can be determined
ElasticSearchHeadIOS[25064:fb03] Connecting to http://localhost:9200/ -- http://localhost:9200/ -- http://localhost:9200/
ElasticSearchHeadIOS[25064:fb03] I restkit.support:RKCache.m:178 Invalidating cache at path: /Users/paulsmith/Library/Application Support/iPhone Simulator/5.1/Applications/BDB8B59F-8307-4F18-A4E7-C55849618D77/Library/Caches/RKClientRequestCache-localhost/SessionStore
ElasticSearchHeadIOS[25064:fb03] I restkit.network.reachability:RKReachabilityObserver.m:155 Reachability observer initialized with hostname localhost
ElasticSearchHeadIOS[25064:fb03] D restkit.network:RKClient.m:271 Reachability observer changed for client <RKClient: 0x8087840>, suspending queue <RKRequestQueue: 0x8087a40 name=(null) suspended=YES requestCount=0 loadingCount=0/5> until reachability to host 'localhost' can be determined
ElasticSearchHeadIOS[25064:fb03] I restkit.network.reachability:RKReachabilityObserver.m:369 Network availability has been determined for reachability observer <RKReachabilityObserver: 0x8088980 host=localhost isReachabilityDetermined=YES isMonitoringLocalWiFi=1039984 reachabilityFlags=-R -----ld>
ElasticSearchHeadIOS[25064:fb03] D restkit.network:RKClient.m:401 Reachability to host 'localhost' determined for client <RKClient: 0x8087840>, unsuspending queue <RKRequestQueue: 0x8087a40 name=(null) suspended=YES requestCount=1 loadingCount=0/5>
ElasticSearchHeadIOS[25064:fb03] D restkit.network:RKRequest.m:435 Sending asynchronous GET request to URL http://localhost:9200/_cluster/state.
ElasticSearchHeadIOS[25064:fb03] T restkit.network:RKRequest.m:381 Prepared GET URLRequest '<NSMutableURLRequest http://localhost:9200/_cluster/state>'. HTTP Headers: {
Accept = "application/json";
"Content-Length" = 0;
}. HTTP Body: .
ElasticSearchHeadIOS[25064:fb03] I restkit.network.reachability:RKReachabilityObserver.m:369 Network availability has been determined for reachability observer <RKReachabilityObserver: 0x6c5c530 host=localhost isReachabilityDetermined=YES isMonitoringLocalWiFi=1039984 reachabilityFlags=-R -----ld>
ElasticSearchHeadIOS[25064:fb03] D restkit.network:RKClient.m:401 Reachability to host 'localhost' determined for client <RKClient: 0x80756e0>, unsuspending queue <RKRequestQueue: 0x8082600 name=(null) suspended=YES requestCount=0 loadingCount=0/5>
ElasticSearchHeadIOS[25064:fb03] D restkit.network:RKResponse.m:195 NSHTTPURLResponse Status Code: 200
ElasticSearchHeadIOS[25064:fb03] D restkit.network:RKResponse.m:196 Headers: {
"Content-Length" = 4462;
"Content-Type" = "application/json; charset=UTF-8";
}
ElasticSearchHeadIOS[25064:fb03] T restkit.network:RKResponse.m:203 Read response body: {"cluster_name":"paul","master_node":"FGewvE3-TEKjXugOGJpWmQ","blocks":{},"nodes":{"FGewvE3-TEKjXugOGJpWmQ":{"name":"Namor the Sub-Mariner","transport_address":"inet[/192.168.0.12:9300]","attributes":{}}},"metadata":{"templates":{},"indices":{"melpaul":{"state":"open","settings":{"index.number_of_replicas":"1","index.number_of_shards":"5","index.version.created":"190299"},"mappings":{"project":{"properties":{"projectAddress":{"type":"string"},"id":{"type":"string"},"suburb":{"type":"string"},"name":{"type":"string"},"state":{"type":"string"},"postalAddress":{"type":"string"},"ownerOrganizationID":{"type":"long"},"shortName":{"type":"string"},"deliveryAddress":{"type":"string"},"country":{"type":"string"}}},"organization":{"properties":{"id":{"type":"string"},"tradingName":{"type":"string"},"name":{"type":"string"},"extParticipant":{"type":"string"},"code":{"type":"string"}}},"task":{"properties":{"aggregateCount":{"type":"long"},"dueDateIso":{"type":"string"},"assignedByUser":{"type":"string"},"pertinent":{"type":"boolean"},"assignedByUserId":{"type":"long"},"assignedBy":{"type":"string"},"projectId":{"type":"long"},"type":{"type":"string"},"id":{"type":"string"},"creationDate":{"type":"long"},"assignedToUserId":{"type":"long"},"description":{"type":"string"},"featureId":{"type":"string"},"aggregated":{"type":"boolean"},"assignedToUser":{"type":"string"},"projectName":{"type":"string"},"dueDate":{"type":"long"},"referenceLabel":{"type":"string"}}},"user":{"properties":{"sortlastName":{"type":"string"},"position":{"type":"string"},"lastName":{"type":"string"},"phone":{"type":"string"},"accessEnabled":{"type":"string"},"orgName":{"type":"string"},"directoryVisibility":{"type":"string"},"id":{"type":"string"},"orgId":{"type":"string"},"orgTradingName":{"type":"string"},"title":{"type":"string"},"divisionName":{"type":"string"},"email":{"type":"string"},"sortfirstName":{"type":"string"},"userName":{"type":"string"},"extParticipant":{"type":"string"},"firstName":{"type":"string"},"accountUnlocked":{"type":"string"},"mobile":{"type":"string"}}}},"aliases":[]}}},"routing_table":{"indices":{"melpaul":{"shards":{"0":[{"state":"STARTED","primary":true,"node":"FGewvE3-TEKjXugOGJpWmQ","relocating_node":null,"shard":0,"index":"melpaul"},{"state":"UNASSIGNED","primary":false,"node":null,"relocating_node":null,"shard":0,"index":"melpaul"}],"1":[{"state":"STARTED","primary":true,"node":"FGewvE3-TEKjXugOGJpWmQ","relocating_node":null,"shard":1,"index":"melpaul"},{"state":"UNASSIGNED","primary":false,"node":null,"relocating_node":null,"shard":1,"index":"melpaul"}],"2":[{"state":"STARTED","primary":true,"node":"FGewvE3-TEKjXugOGJpWmQ","relocating_node":null,"shard":2,"index":"melpaul"},{"state":"UNASSIGNED","primary":false,"node":null,"relocating_node":null,"shard":2,"index":"melpaul"}],"3":[{"state":"STARTED","primary":true,"node":"FGewvE3-TEKjXugOGJpWmQ","relocating_node":null,"shard":3,"index":"melpaul"},{"state":"UNASSIGNED","primary":false,"node":null,"relocating_node":null,"shard":3,"index":"melpaul"}],"4":[{"state":"STARTED","primary":true,"node":"FGewvE3-TEKjXugOGJpWmQ","relocating_node":null,"shard":4,"index":"melpaul"},{"state":"UNASSIGNED","primary":false,"node":null,"relocating_node":null,"shard":4,"index":"melpaul"}]}}}},"routing_nodes":{"unassigned":[{"state":"UNASSIGNED","primary":false,"node":null,"relocating_node":null,"shard":0,"index":"melpaul"},{"state":"UNASSIGNED","primary":false,"node":null,"relocating_node":null,"shard":1,"index":"melpaul"},{"state":"UNASSIGNED","primary":false,"node":null,"relocating_node":null,"shard":2,"index":"melpaul"},{"state":"UNASSIGNED","primary":false,"node":null,"relocating_node":null,"shard":3,"index":"melpaul"},{"state":"UNASSIGNED","primary":false,"node":null,"relocating_node":null,"shard":4,"index":"melpaul"}],"nodes":{"FGewvE3-TEKjXugOGJpWmQ":[{"state":"STARTED","primary":true,"node":"FGewvE3-TEKjXugOGJpWmQ","relocating_node":null,"shard":0,"index":"melpaul"},{"state":"STARTED","primary":true,"node":"FGewvE3-TEKjXugOGJpWmQ","relocating_node":null,"shard":1,"index":"melpaul"},{"state":"STARTED","primary":true,"node":"FGewvE3-TEKjXugOGJpWmQ","relocating_node":null,"shard":2,"index":"melpaul"},{"state":"STARTED","primary":true,"node":"FGewvE3-TEKjXugOGJpWmQ","relocating_node":null,"shard":3,"index":"melpaul"},{"state":"STARTED","primary":true,"node":"FGewvE3-TEKjXugOGJpWmQ","relocating_node":null,"shard":4,"index":"melpaul"}]}},"allocations":[]}
ElasticSearchHeadIOS[25064:1400b] D restkit.network:RKObjectLoader.m:262 Beginning object mapping activities within GCD queue labeled: org.restkit.ObjectMapping
ElasticSearchHeadIOS[25064:1400b] D restkit.network:RKObjectLoader.m:250 No object mapping provider, using mapping provider from parent object manager to perform KVC mapping
ElasticSearchHeadIOS[25064:1400b] T restkit.network:RKObjectLoader.m:187 bodyAsString: {"cluster_name":"paul","master_node":"FGewvE3-TEKjXugOGJpWmQ","blocks":{},"nodes":{"FGewvE3-TEKjXugOGJpWmQ":{"name":"Namor the Sub-Mariner","transport_address":"inet[/192.168.0.12:9300]","attributes":{}}},"metadata":{"templates":{},"indices":{"melpaul":{"state":"open","settings":{"index.number_of_replicas":"1","index.number_of_shards":"5","index.version.created":"190299"},"mappings":{"project":{"properties":{"projectAddress":{"type":"string"},"id":{"type":"string"},"suburb":{"type":"string"},"name":{"type":"string"},"state":{"type":"string"},"postalAddress":{"type":"string"},"ownerOrganizationID":{"type":"long"},"shortName":{"type":"string"},"deliveryAddress":{"type":"string"},"country":{"type":"string"}}},"organization":{"properties":{"id":{"type":"string"},"tradingName":{"type":"string"},"name":{"type":"string"},"extParticipant":{"type":"string"},"code":{"type":"string"}}},"task":{"properties":{"aggregateCount":{"type":"long"},"dueDateIso":{"type":"string"},"assignedByUser":{"type":"string"},"pertinent":{"type":"boolean"},"assignedByUserId":{"type":"long"},"assignedBy":{"type":"string"},"projectId":{"type":"long"},"type":{"type":"string"},"id":{"type":"string"},"creationDate":{"type":"long"},"assignedToUserId":{"type":"long"},"description":{"type":"string"},"featureId":{"type":"string"},"aggregated":{"type":"boolean"},"assignedToUser":{"type":"string"},"projectName":{"type":"string"},"dueDate":{"type":"long"},"referenceLabel":{"type":"string"}}},"user":{"properties":{"sortlastName":{"type":"string"},"position":{"type":"string"},"lastName":{"type":"string"},"phone":{"type":"string"},"accessEnabled":{"type":"string"},"orgName":{"type":"string"},"directoryVisibility":{"type":"string"},"id":{"type":"string"},"orgId":{"type":"string"},"orgTradingName":{"type":"string"},"title":{"type":"string"},"divisionName":{"type":"string"},"email":{"type":"string"},"sortfirstName":{"type":"string"},"userName":{"type":"string"},"extParticipant":{"type":"string"},"firstName":{"type":"string"},"accountUnlocked":{"type":"string"},"mobile":{"type":"string"}}}},"aliases":[]}}},"routing_table":{"indices":{"melpaul":{"shards":{"0":[{"state":"STARTED","primary":true,"node":"FGewvE3-TEKjXugOGJpWmQ","relocating_node":null,"shard":0,"index":"melpaul"},{"state":"UNASSIGNED","primary":false,"node":null,"relocating_node":null,"shard":0,"index":"melpaul"}],"1":[{"state":"STARTED","primary":true,"node":"FGewvE3-TEKjXugOGJpWmQ","relocating_node":null,"shard":1,"index":"melpaul"},{"state":"UNASSIGNED","primary":false,"node":null,"relocating_node":null,"shard":1,"index":"melpaul"}],"2":[{"state":"STARTED","primary":true,"node":"FGewvE3-TEKjXugOGJpWmQ","relocating_node":null,"shard":2,"index":"melpaul"},{"state":"UNASSIGNED","primary":false,"node":null,"relocating_node":null,"shard":2,"index":"melpaul"}],"3":[{"state":"STARTED","primary":true,"node":"FGewvE3-TEKjXugOGJpWmQ","relocating_node":null,"shard":3,"index":"melpaul"},{"state":"UNASSIGNED","primary":false,"node":null,"relocating_node":null,"shard":3,"index":"melpaul"}],"4":[{"state":"STARTED","primary":true,"node":"FGewvE3-TEKjXugOGJpWmQ","relocating_node":null,"shard":4,"index":"melpaul"},{"state":"UNASSIGNED","primary":false,"node":null,"relocating_node":null,"shard":4,"index":"melpaul"}]}}}},"routing_nodes":{"unassigned":[{"state":"UNASSIGNED","primary":false,"node":null,"relocating_node":null,"shard":0,"index":"melpaul"},{"state":"UNASSIGNED","primary":false,"node":null,"relocating_node":null,"shard":1,"index":"melpaul"},{"state":"UNASSIGNED","primary":false,"node":null,"relocating_node":null,"shard":2,"index":"melpaul"},{"state":"UNASSIGNED","primary":false,"node":null,"relocating_node":null,"shard":3,"index":"melpaul"},{"state":"UNASSIGNED","primary":false,"node":null,"relocating_node":null,"shard":4,"index":"melpaul"}],"nodes":{"FGewvE3-TEKjXugOGJpWmQ":[{"state":"STARTED","primary":true,"node":"FGewvE3-TEKjXugOGJpWmQ","relocating_node":null,"shard":0,"index":"melpaul"},{"state":"STARTED","primary":true,"node":"FGewvE3-TEKjXugOGJpWmQ","relocating_node":null,"shard":1,"index":"melpaul"},{"state":"STARTED","primary":true,"node":"FGewvE3-TEKjXugOGJpWmQ","relocating_node":null,"shard":2,"index":"melpaul"},{"state":"STARTED","primary":true,"node":"FGewvE3-TEKjXugOGJpWmQ","relocating_node":null,"shard":3,"index":"melpaul"},{"state":"STARTED","primary":true,"node":"FGewvE3-TEKjXugOGJpWmQ","relocating_node":null,"shard":4,"index":"melpaul"}]}},"allocations":[]}
ElasticSearchHeadIOS[25064:1400b] willMapData
ElasticSearchHeadIOS[25064:fb03] did finish loading
好了,表格视图显示了从上述调用中返回的映射数据现在已经完成,我可以在屏幕上正确地看到结果。
I restkit.support:RKCache.m:178 Invalidating cache at path: /Users/paulsmith/Library/Application Support/iPhone Simulator/5.1/Applications/BDB8B59F-8307-4F18-A4E7-C55849618D77/Library/Caches/RKClientRequestCache-localhost/SessionStore
I restkit.network.reachability:RKReachabilityObserver.m:155 Reachability observer initialized with hostname localhost
D restkit.network:RKClient.m:271 Reachability observer changed for client <RKClient: 0x808ce90>, suspending queue <RKRequestQueue: 0x80834c0 name=(null) suspended=YES requestCount=0 loadingCount=0/5> until reachability to host 'localhost' can be determined
D restkit.network:RKClient.m:256 Reachability observer changed for RKClient <RKClient: 0x80756e0>, disposing of previous instance: <RKReachabilityObserver: 0x6c5c530 host=localhost isReachabilityDetermined=YES isMonitoringLocalWiFi=1039984 reachabilityFlags=-R -----ld>
Connecting to http://localhost:9200/ -- http://localhost:9200/ -- http://localhost:9200/
I restkit.support:RKCache.m:178 Invalidating cache at path: /Users/paulsmith/Library/Application Support/iPhone Simulator/5.1/Applications/BDB8B59F-8307-4F18-A4E7-C55849618D77/Library/Caches/RKClientRequestCache-localhost/SessionStore
I restkit.network.reachability:RKReachabilityObserver.m:155 Reachability observer initialized with hostname localhost
D restkit.network:RKClient.m:271 Reachability observer changed for client <RKClient: 0x81b0bc0>, suspending queue <RKRequestQueue: 0x81b0d20 name=(null) suspended=YES requestCount=0 loadingCount=0/5> until reachability to host 'localhost' can be determined
D restkit.network:RKClient.m:256 Reachability observer changed for RKClient <RKClient: 0x81b0bc0>, disposing of previous instance: <RKReachabilityObserver: 0x81b1c80 host=localhost isReachabilityDetermined=NO isMonitoringLocalWiFi=1039984 reachabilityFlags=-- ------->
I restkit.network.reachability:RKReachabilityObserver.m:369 Network availability has been determined for reachability observer <RKReachabilityObserver: 0x807f2f0 host=localhost isReachabilityDetermined=YES isMonitoringLocalWiFi=1039984 reachabilityFlags=-R -----ld>
D restkit.network:RKClient.m:401 Reachability to host 'localhost' determined for client <RKClient: 0x808ce90>, unsuspending queue <RKRequestQueue: 0x80834c0 name=(null) suspended=YES requestCount=0 loadingCount=0/5>
这是模拟器中它的样子的Jing screencast(你可以看到第一次调用委托方法的断点,但第二次没有调用)
答案 0 :(得分:1)
这是一个保留问题。您正在创建对象的本地副本,而不是将其分配给导致其保留的任何内容。这可能是RKObjectManager等。创建一个属性,如myObjectManager,并像这样分配 self.myObjectManager = [[RkObjectManager alloc] init];
确保您学习并了解内存管理。使用ARC,但您仍需要对内存管理有基本的了解!
HTH
答案 1 :(得分:1)
我也在文档中找到了这个方法:loadObjectsAtResourcePath:usingBlock:但我不能使用它,因为它告诉我:'RKObjectManager'没有可见的@interface声明...如果你试图定位核心数据,那么你我想使用RKManagedObjectRequestOperation和managedObjectRequestOperationWithRequest:success:failure :.还有其他示例.... Restkit Post不发送对象·1·PUT请求,更改标题并保存...