Skip to content

Instantly share code, notes, and snippets.

@Sunnyztj
Created January 6, 2014 02:19
Show Gist options
  • Save Sunnyztj/8277208 to your computer and use it in GitHub Desktop.
Save Sunnyztj/8277208 to your computer and use it in GitHub Desktop.
Objective C connect with Rails servers
- (NSDictionary*) fetchMessageList:(NSInteger)pagenum {
NSString* urlstring = [NSString stringWithFormat:@"%@/api/v1/user/messages.json?page=%d", BaseURL, pagenum];
NSLog(@"Message List URL : %@", urlstring);
NSURL* url = [NSURL URLWithString:urlstring];
MBGetDataRequest* request = [MBGetDataRequest requestWithURL:url];
[request applyHTTPHeaders:[NSDictionary dictionaryWithObjectsAndKeys:
[[MBPreferenceManager sharedPreferenceManager] getSecurityKey],
@"Http-X-User-Access-Token",
@"application/x-www-form-urlencoded",
@"Content-Type", nil]];
[request startSynchronous];
NSString* response = [request responseString];
NSDictionary* retary=nil;
if (response) {
retary = [MBUtilities stringConvertToJSON:response];
if ([self checkResponse:retary]) {
return retary;
} else {
return nil;
}
}
return retary;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment