2013-01-07 3 views
1

AFNetworking을 사용하여 응용 프로그램을 개발하기 시작했습니다. 핵심 데이터를 사용할 때까지 모든 것이 잘되었습니다. 거기에 추가 클래스 (AFIncrementalStore)가 있다는 것을 알고 있습니다. 하지만 저는 IOS 개발에 익숙하지 않았기 때문에 이에 대한 많은 정보가 없습니다. RestKit으로 전환하기로 결정한 이유는 여기에 더 많은 정보가 있기 때문입니다. 이제 AFNetworking에 대한 자습서를 읽었습니다. 여기에이 메서드가 포함 된 API 클래스가 만들어졌습니다.AFNetworking에서 RestKit으로 전환

+(API *)sharedInstance 
{ 
    static API *sharedInstance = nil; 
    static dispatch_once_t oncePredicate; 
    dispatch_once(&oncePredicate,^{ 
     sharedInstance = [[self alloc]initWithBaseURL:[NSURL URLWithString:kAPIHost]]; 
    }); 
    return sharedInstance; 
} 

#pragma mark - init 
//intialize the API class with the destination host name 

-(API *)init 
{ 
    //call super init 
    self = [super init]; 

    if (self != nil){ 
     //initialize the object 
     user = nil; 

     [self registerHTTPOperationClass:[AFJSONRequestOperation class]]; 

     // Accept HTTP Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1 
     [self setDefaultHeader:@"Accept" value:@"application/json"]; 
    } 
    return self; 
} 

-(void)loginCommand:(NSMutableDictionary *)params onCompletion:(JSONResponseBlock)completionBlock{ 
    NSLog(@"%@%@",kAPIHost,kAPILogin); 
    NSMutableURLRequest *apiRequest = [self multipartFormRequestWithMethod:@"POST" path:kAPILogin parameters:params constructingBodyWithBlock:^(id <AFMultipartFormData>formData){ 
     //TODO: attach file if needed 

    }]; 
    AFJSONRequestOperation *operation = [[AFJSONRequestOperation alloc] initWithRequest:apiRequest]; 
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject){ 
     //success! 
     NSLog(@"SUCCESSSS!"); 
     completionBlock(responseObject); 
    }failure:^(AFHTTPRequestOperation *operation, NSError *error){ 
     //Failure 
     NSLog(@"FAILUREE!"); 
     completionBlock([NSDictionary dictionaryWithObject:[error localizedDescription] forKey:@"error"]); 
    }]; 
    [operation start]; 

} 

내 웹 서비스와 응용 프로그램 간의 통신을 처리합니다. viewController 자체에서이 메서드를 이렇게 호출합니다.

/* [[API sharedInstance] loginCommand:[NSMutableDictionary dictionaryWithObjectsAndKeys:_txtLogin.text,@"email",_txtPass.text,@"pwd", nil] onCompletion:^(NSDictionary *json){ 
    //completion 
     if(![json objectForKey:@"error"]){ 
      NSLog(@"status %@",[json valueForKeyPath:@"data.status"]); 
      if([[json valueForKeyPath:@"data.status"]intValue] == 200){ 
        // Everything is oké, and login is succesfull 
      }else{ 
       //show validation 
      } 
     }else { 
      NSLog(@"Cannot connect to the server"); 
     } 
    }];*/ 

이것이 AFnetworking에서 수행하는 방법입니다. 그러나 RestKit에서이 작업을 수행 할 때의 차이점은 무엇입니까? 나는 튜토리얼을 수색했다. 그러나 RestKit 1.0에서 2.0으로 업데이트 한 후에는 많은 자습서가 시대에 뒤쳐져 있습니다. 그래서 아무도 나를 도와 줄 수 있기를 바랍니다!

친절에 감사드립니다!

답변

0

이 자습서를 사용하여 RestKit을 사용했습니다. 그것을 사용하는 방법을 보여줍니다 그리고 당신은 다른 세부 사항을 배울 수 있습니다. http://www.youtube.com/watch?v=dFi9t8NW0oY

+0

링크 전용 답변을 게시하지 마십시오. 예기치 않게 사라지고 내용을 검색 할 수 없으며 실제로 질문에 대답하는지 여부를 알기가 어렵습니다. –

관련 문제