如何使用RestKit進行同步請求?如何在RestKit中創建同步請求?
我用這樣的方式早些時候(SBJSON):
UIDevice *myDevice = [UIDevice currentDevice];
NSString *deviceUDID = [myDevice uniqueIdentifier];
double v = [[[UIDevice currentDevice] systemVersion]doubleValue];
NSString *version=[NSString stringWithFormat:@"%@ %.1f",deviceType,v];
NSString *encodedParam1 =[version stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *requestString = [NSString stringWithFormat:@"method=views.get&view_name=client_list",nil];
NSData *requestData = [NSData dataWithBytes: [requestString UTF8String] length: [requestString length]];
NSString *urlString = [NSString stringWithFormat:@"http://localhost/index.php?oper=StoreDeviceId&device_id=%@&device_version=%@",deviceUDID,encodedParam1];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod: @"POST"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody: requestData];
//Data returned by WebService
NSData *returnData = [NSURLConnection sendSynchronousRequest: request returningResponse: nil error: nil ];
[request release];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding: NSUTF8StringEncoding];
NSDictionary *dict1 = [returnString JSONValue];
相同的操作如何使用restkit框架來處理。
先感謝
mmm如果您確定應用程序在服務器處理請求時會凍結,您確定要這麼做嗎?你可以在Restkit中使用塊,這樣你就可以將代碼編寫爲「同步」,但你會得到異步 – clopez
我的答案是否適合你? – clopez