私はrestKitを初めて使用します。いくつか質問があります。json/xml を使用して Post リクエストを Web サービスに送信し、着信応答をクラスにマップする方法がわかりません。誰でも私にそれについて助けてもらえますか。私が使用しているコードは次のとおりです。私の applicationDelegate では、ベース URL を提供する RKObjectManager をインスタンス化しています。
RKObjectManager* manager = [RKObjectManager objectManagerWithBaseURL:@"https://example.com/services/"];
// Request params in Dictionary
NSArray *objects = [NSArray arrayWithObjects: email, password,
nil];
NSArray *keys = [NSArray arrayWithObjects:@"username",
@"password", nil];
NSDictionary *params = [NSDictionary dictionaryWithObjects:objects
forKeys:keys];
NSLog(@"Manager: %@", [RKObjectManager
sharedManager].description);
// User object Mapping
RKObjectMapping* userMapping = [RKObjectMapping mappingForClass:
[User class]];
[userMapping mapKeyPath:@"userName" toAttribute:@"userName"];
[userMapping mapKeyPath:@"lastName" toAttribute:@"lastName"];
[userMapping mapKeyPath:@"active" toAttribute:@"active"];
[[RKObjectManager sharedManager].mappingProvider
setMapping:userMapping forKeyPath:@"user"];
[[RKObjectManager sharedManager] loadObjectsAtResourcePath:@"/
login" delegate:self];
投稿が /login に送信されると、サーバーは有効な json を送り返し、その json を User クラスにマップする必要があります。
- (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:
(NSArray*)objects {
RKLogInfo(@"Load collection of Articles: %@", objects);
}
- (void)objectLoader:(RKObjectLoader*)objectLoader didFailWithError:
(NSError *)error
{
NSLog(@"Objecy Loader failed: %@", error);
}
- (void)request:(RKRequest *)request didFailLoadWithError:(NSError
*)error
{
NSLog(@"Request failed");
}
- (void)request:(RKRequest*)request didLoadResponse:
(RKResponse*)response {
if ([request isGET]) {
// Handling GET /foo.xml
if ([response isOK]) {
// Success! Let's take a look at the data
NSLog(@"Retrieved XML: %@", [response bodyAsString]);
}
} else if ([request isPOST]) {
// Handling POST /other.json
if ([response isXML]) {
///NSLog(@"Seng a JSON request:! \n %@", [request
HTTPBodyString]);
NSLog(@"Got a responce! \n %@", [response bodyAsString]);
}
} else if ([request isDELETE]) {
// Handling DELETE /missing_resource.txt
if ([response isNotFound]) {
NSLog(@"The resource path '%@' was not found.", [request
resourcePath]);
}
}
}
私がそれを実行すると、objectLoaderメソッドはトリガーされません.restkitについての私の理解は、いつ呼び出されるかということです
[[RKObjectManager sharedManager] loadObjectsAtResourcePath:@"/login"
delegate:self];
実行されますか?どんな助けでも大歓迎です:)