Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 如何在RestKit中发出同步请求?_Objective C_Ios_Restkit - Fatal编程技术网

Objective c 如何在RestKit中发出同步请求?

Objective c 如何在RestKit中发出同步请求?,objective-c,ios,restkit,Objective C,Ios,Restkit,如何使用同步请求 我在前面使用了这种方式(SBJSON): 使用restkit框架处理相同的操作 提前感谢要使用RestKit发出同步请求,请在正常设置RKRequest实例后使用RKRequest的-sendSynchronously方法 要使用RestKit发出同步请求,请在正常设置RKRequest实例后,使用RKRequest的-sendSynchronously方法 下面是一个使用RKClient的同步post示例 //Configure RKLog RKLogConfigureByN

如何使用同步请求

我在前面使用了这种方式(SBJSON):

使用restkit框架处理相同的操作


提前感谢

要使用RestKit发出同步请求,请在正常设置
RKRequest
实例后使用
RKRequest
-sendSynchronously
方法

要使用RestKit发出同步请求,请在正常设置
RKRequest
实例后,使用
RKRequest
-sendSynchronously
方法

下面是一个使用RKClient的同步post示例

//Configure RKLog
RKLogConfigureByName("RestKit/Network", RKLogLevelTrace);

//Set Client
RKClient *client = [RKClient clientWithBaseURLString:@"some_base_url"];

//Params to be send
NSDictionary *queryParameters = [NSDictionary dictionaryWithObjectsAndKeys:@"1",@"first_value",@"2",@"second_value",nil];

//Prepare the request and send it
RKRequest *request = [client post:@"path" params:queryParameters delegate:nil];
RKResponse *response = [request sendSynchronously];

//Process the response
NSString *stringResponse = [[NSString alloc] initWithData:[response body] encoding: NSUTF8StringEncoding];
NSDictionary *dict1 = [stringResponse JSONValue];

但是我建议使用异步调用来代替块

下面是一个使用RKClient的同步post示例

//Configure RKLog
RKLogConfigureByName("RestKit/Network", RKLogLevelTrace);

//Set Client
RKClient *client = [RKClient clientWithBaseURLString:@"some_base_url"];

//Params to be send
NSDictionary *queryParameters = [NSDictionary dictionaryWithObjectsAndKeys:@"1",@"first_value",@"2",@"second_value",nil];

//Prepare the request and send it
RKRequest *request = [client post:@"path" params:queryParameters delegate:nil];
RKResponse *response = [request sendSynchronously];

//Process the response
NSString *stringResponse = [[NSString alloc] initWithData:[response body] encoding: NSUTF8StringEncoding];
NSDictionary *dict1 = [stringResponse JSONValue];

但是我建议使用异步调用来代替块

你能给出该请求和响应操作的示例代码吗?你能给出该请求和响应操作的示例代码吗?如果你这样做,你的应用程序将在服务器处理该请求时冻结,你确定要这样做吗?您可以将块与Restkit一起使用,这样您就可以将代码编写为“同步”代码,但您得到的是异步的。我的答案对您有用吗?嗯,如果这样做,您的应用程序将在服务器处理请求时冻结,您确定要这样做吗?您可以将块与Restkit结合使用,这样您就可以将代码编写为“同步”代码,但您可以异步编写代码。我的答案对您有用吗?