23

私はObjective-CとXCodeにはかなり慣れていませんが、RestKitにはさらに慣れていますが、Javaで12年間プログラミングを行っています。

iOSアプリをRestKitに接続していて、RESTサーバーからロードするアクションが最初にのみ機能します。ナビゲーションコントローラーに戻って同じ操作を再試行すると、loadObjectsAtResourcePath:delegateメソッドが呼び出されますが、デリゲートメソッドはありません。呼び出されます(そして、それらが発生したときにログに記録するために、それらすべてを実装しました)。

Restkitの基本的な何か、そしておそらくそれの非同期性を見逃していると感じます。これは、マッピングが最初は明らかに正常に機能しているため、後続の呼び出しが非同期キューで失われる必要があるためです。

私はこれをグーグルで検索し、似たような人々が似たようなもので立ち往生しているのを見ましたが、それらすべてを試しましたが、違いはないようです。キャッシングが無効になり、objectLoaderDidLoadUnexpectedResponse呼び出さdidFailWithErrorれることはなく、床に落とされます。

コードソース:

私のXCodeプロジェクトはここのgithubにあります

ロード呼び出しを実行する特定のViewControllerはここにあります(setUpRestKitメソッドを参照)

呼び出しのシーケンスは次のようになります。

  • ユーザーがホスト名とポートを入力し、[接続]をクリックします
  • ESRKConnectionViewController.mは、 prepareForSegueを介して呼び出しを取得し、このアドレスを使用して共有RKClientを設定します(後でRKClientがあまり使用されていないことがわかりますが、RKOBjectManagerはbaseURLだけを取得するようであるため、少し冗長です)
  • 次に、 ESRKServerViewController.mはRKObjectManagerにマッピングを設定し、 loadObjectsAtResourcePathを呼び出して、それ自体をデリゲートとして渡します(はい、おそらくこれらのマッピングはApp Delegateで最初に構成する必要があることを認識していますが、これを再度設定する方法がわかりません単なる冗長コード以上のもの)
  • 次に、objectLoader:didLoadObjectsコールバックが、マップされたオブジェクトの取得とテーブルビューのモデルの構成を担当します。これは1回だけ発生します。

ログを有効にすると、これは私が見るパターンであり、最初の呼び出しが完了したとき、および2番目の呼び出しが開始したときなどに注釈が付けられます(ここでは明確にするためにタイムスタンプがトリミングされています)。

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スクリーンキャストです(デリゲートメソッドのブレークポイントが最初に呼び出されるのを見ることができますが、2番目は何も呼び出されません)

4

2 に答える 2

1

これは保持の問題です。オブジェクトのローカル コピーを作成していて、それを保持する原因となるものには割り当てていません。これはおそらく RKObjectManager などです。myObjectManager などのプロパティを作成し、このように割り当てます self.myObjectManager = [[RkObjectManager alloc] init];

メモリ管理を学習して理解するようにしてください。ARC を使用しますが、メモリ管理の基本的な理解が必要です。

HTH

于 2013-06-06T14:46:09.343 に答える
1

ドキュメントにもこのメソッドがあります: loadObjectsAtResourcePath:usingBlock: しかし、「RKObjectManager」宣言の目に見える @interface がありません ... コア データをターゲットにしようとしている場合は、 RKManagedObjectRequestOperation と managedObjectRequestOperationWithRequest:success:failure: を使用します。... で利用可能な追加の例があります。 オブジェクトを送信しない Restkit ポスト · 1 · PUT リクエスト、ヘッダーを変更して保存 ...

于 2013-06-06T14:49:21.967 に答える