RestKit Put服务不会影响服务器上的数据库数据,即使响应成功也是如此

时间:2014-07-23 11:59:03

标签: ios objective-c restkit

我正在开发iPhone应用程序并使用Restkit来消费服务并将数据放在服务器上。我第一次使用Restkit。我想将数据放在服务器上然后我实现了restkit put方法,并且它成功执行并获得响应" SUCCESS"但是当我检索数据时,它不会影响数据意味着不会在服务器上获得最后一次放置数据。所以有人能告诉我这有什么问题吗?我使用了以下代码:

////Response Mapping values
    RKObjectMapping *responseMapping = [RKObjectMapping mappingForClass:[NSMutableArray class]];
    [responseMapping addAttributeMappingsFromArray:@[@"SenderId", @"SentDate", @"Status",@"GroupId", @"Message"]];

    //Request Mapping values
    RKObjectMapping *requestMapping = [RKObjectMapping requestMapping]; // objectClass == NSMutableDictionary
    [requestMapping addAttributeMappingsFromArray:@[@"SenderId", @"SentDate", @"Status",@"GroupId", @"Message"]];

    ITRestKitServices *restkitService = [[ITRestKitServices alloc] initWithDelegate:self];
    [restkitService putDataONserverBulletin:bulletinMutableArray pathPattern:@"bulletin" keyPath:@"" userName:appDelegate.user.Email password:appDelegate.user.SessionToken requestMapping:requestMapping responseMapping:responseMapping];

//以下代码将数据放在我使用的服务器上:

        // initialize AFNetworking HTTPClient
    NSURL *baseURL = [NSURL URLWithString:BASE_URL_STRING];
    AFHTTPClient *client = [[AFHTTPClient alloc] initWithBaseURL:baseURL];

    [client setAuthorizationHeaderWithUsername:userName password:password];

    //set pathPattern
    NSString *path = [NSString stringWithFormat:@"%@/%@",BASE_PATH_STRING,pathPattern];

    //StatusCodes
    NSIndexSet *statusCodes = RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful);

    //Request Descriptor
    RKRequestDescriptor *requestDescriptor =
    [RKRequestDescriptor requestDescriptorWithMapping:requestMapping
                                          objectClass:[Bulletin class]
                                          rootKeyPath:nil
                                               method:RKRequestMethodPUT];
    //Response Descriptor
    RKResponseDescriptor *userResponseDescriptor =
    [RKResponseDescriptor responseDescriptorWithMapping:responseMapping
                                                 method:RKRequestMethodPUT
                                            pathPattern:path
                                                keyPath:keyPath
                                            statusCodes:statusCodes];


    RKObjectManager *objectManager = [[RKObjectManager alloc] initWithHTTPClient:client];

    [objectManager addRequestDescriptor:requestDescriptor];

    [objectManager addResponseDescriptor:userResponseDescriptor];

    AppDelegate *appDelegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];
    if(appDelegate.isLoading == NO)
    {
        [appDelegate startLoading];
    }

    [objectManager putObject:dataObject
                        path:path
                  parameters:nil
                     success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult)
     {
         NSLog(@"Bulletin Success");
     }
     failure:^(RKObjectRequestOperation *operation, NSError *error)
     {
         if(appDelegate.isLoading == YES)
         {
             [appDelegate stopLoading];
         }
         NSLog(@">>> Error: %@", error);
     }];

0 个答案:

没有答案