0
在我的第一視圖控制器(MonitorViewController),這是在接口文件MonitorViewController.h:在IOS 5消耗RESTful Web服務
#import <RestKit/RestKit.h>
@interface MonitorViewController : UIViewController <RKRequestDelegate>
在MonitorViewController.m viewDidLoad方法,我這個底:
RKClient* client = [RKClient clientWithBaseURL:@"http://192.168.2.3:8000/DataRecorder/ExternalControl"];
NSLog(@"I am your RKClient singleton : %@", [RKClient sharedClient]);
[client get:@"/json/get_Signals" delegate:self];
的委託方法MonitorViewController.m實施:
- (void) request: (RKRequest *) request didLoadResponse: (RKResponse *) response {
if ([request isGET]) {
NSLog (@"Retrieved : %@", [response bodyAsString]);
}
}
- (void) request:(RKRequest *)request didFailLoadWithError:(NSError *)error
{
NSLog (@"Retrieved an error");
}
- (void) requestDidTimeout:(RKRequest *)request
{
NSLog(@"Did receive timeout");
}
- (void) request:(RKRequest *)request didReceivedData:(NSInteger)bytesReceived totalBytesReceived:(NSInteger)totalBytesReceived totalBytesExectedToReceive:(NSInteger)totalBytesExpectedToReceive
{
NSLog(@"Did receive data");
}
我的AppDelegate方法DidFinishLaunchingWithOptions方法只返回YES而沒有其他東西。
它會幫助我區分哪個響應對應於哪個請求,如果我發送10請求是這樣的: http://mywebservice.com/myservice?dev=1 http://mywebservice.com/myservice?dev=2 ... http://mywebservice.com/myservice?dev= 10 – Torben 2012-02-20 14:02:13
是的,但如果您的Web服務沒有真正使用* dev *參數,我不推薦使用它。看到我更新的答案。 – lawicko 2012-02-20 15:00:01
也許我沒有解釋得很清楚。我會再試一次:-) – Torben 2012-02-22 12:49:56