Restkit:没有调用RKRequest代理

时间:2013-01-14 21:14:54

标签: ios web-services delegates restkit

我真的被这个问题困扰了。我正在使用Restkit来访问Web服务。大多数操作都运行正常,但前两个,intializeDevice和insertNewPatron不是。对于这些,将触发异步请求,但永远不会调用委托方法。我已检查过服务器,并且没有证据表明正在进行这些调用。我无法分辨这些使它们不起作用的操作有什么不同。这是进行调用的类:

-(id)initForController:(UIViewController *)viewController{
    self.vc=viewController;
    NSString *baseURL = @"https://xxxxxxxxx/APNS_WebService/rest/operations/";
    NSURL *url=[NSURL URLWithString:baseURL];

    client = [RKClient clientWithBaseURL:url];
    client.disableCertificateValidation=YES;

    return self;
}

-(void)insertNewPatronWithCard:(NSString *)cardNumber PIN:(NSString *)pin NickName:(NSString *)nickname Device:(NSString *)deviceID{


    request = [client requestWithResourcePath:[NSString stringWithFormat:@"/insertNewPatron?cardNumber=%@&pin=%@&nickname=%@&deviceID=%@",cardNumber,pin,nickname,deviceID]];
    NSDictionary *params = [NSDictionary dictionaryWithObject:@"insertNewPatron" forKey:@"operation"];
    request.params=params;
    request.delegate=self;
    [request sendAsynchronously];


}

-(void)initializeDeviceWithID:(NSString *)deviceID{



    request = [client requestWithResourcePath:[NSString stringWithFormat:@"/initializeDevice?deviceID=%@",deviceID]];
    NSDictionary *params = [NSDictionary dictionaryWithObject:@"initializeDevice" forKey:@"operation"];
    request.params=params;
    request.delegate=self;
    [request sendAsynchronously];


}

-(void)updateDevicePreferencesWithDeviceID:(NSString *)deviceID DueDateNotice:(NSString *)dueDateNotice HoldsNotice:(NSString *)holdsNotice EventNotice:(NSString *)eventNotice{


    request = [client requestWithResourcePath:[NSString stringWithFormat:@"/updateDevicePreferences?deviceID=%@&dueDateNotice=%@&holdsNotice=%@&eventNotice=%@",deviceID,dueDateNotice,holdsNotice,eventNotice]];
    NSDictionary *params = [NSDictionary dictionaryWithObject:@"updateDevicePreferences" forKey:@"operation"];
    request.params=params;
    request.delegate=self;
    [request sendAsynchronously];


}

-(void)removeUserWithCard:(NSString *)cardNumber{


    request = [client requestWithResourcePath:[NSString stringWithFormat:@"/removeUser?cardNumber=%@",cardNumber]];
    NSDictionary *params = [NSDictionary dictionaryWithObject:@"removeUser" forKey:@"operation"];
    request.params=params;
    request.delegate=self;
   [request sendAsynchronously];


}

-(void)addEventWithDevice:(NSString *)deviceID EventID:(NSString *)eventID{



    request = [client requestWithResourcePath:[NSString stringWithFormat:@"/addEvent?deviceID=%@&eventID=%@",deviceID,eventID]];
    NSDictionary *params = [NSDictionary dictionaryWithObject:@"addEvent" forKey:@"operation"];
    request.params=params;
    request.delegate=self;
    [request send];


}

-(void)removeEventWithDevice:(NSString *)deviceID EventID:(NSString *)eventID{


   request = [client requestWithResourcePath:[NSString stringWithFormat:@"/removeEvent?deviceID=%@&eventID=%@",deviceID,eventID]];
    NSDictionary *params = [NSDictionary dictionaryWithObject:@"removeEvent" forKey:@"operation"];
    request.params=params;
    request.delegate=self;
     [request sendAsynchronously];

}

-(void)removeAllEventsWithDevice:(NSString *)deviceID{


    request = [client requestWithResourcePath:[NSString stringWithFormat:@"/removeAllEvents?deviceID=%@",deviceID]];
    request.delegate=self;
    NSDictionary *params = [NSDictionary dictionaryWithObject:@"removeAllEvents" forKey:@"operation"];
    request.params=params;

   [request sendAsynchronously];


}

我注意到对于那些不起作用的操作,在Restkit日志记录中,我收到的消息是“Prepared GET UrlRequest”,但不是那个说“继续请求”的消息,我在操作中看到了那工作。

1 个答案:

答案 0 :(得分:1)

您是否使用断点检查所有变量是否正确?没有零代表或你缺少的东西?你是在做隔离的请求还是在另一个电话的同时进行?

您的某个电话可能会在此过程中失去代理人。我建议使用而不是委托范例来避免竞争条件。

希望它有所帮助!