Wednesday, May 1, 2013

NSURL initWithScheme example ios


initWithScheme :host:path:

Initializes a newly created NSURL with a specified scheme, host, and path.
- (id)initWithScheme:(NSString *)scheme host:(NSString *)host path:(NSString*)path
Parameters of [NSURL initWithScheme]
scheme
The scheme for the NSURL object.
host
The host for the NSURL object. May be the empty string.
path
The path for the NSURL object. If path begins with a tilde, it must first be expanded withstringByExpandingTildeInPath.
Return Value of [NSURL initWithScheme]
The newly initialized NSURL object.
Example of [NSURL initWithScheme]
NSString *urlToPublish = [@"http://stackoverflow.com" URLEscapedString_ch];
NSString *host = @"example.host.com";
NSString *urlString = [NSString stringWithFormat:@"/SetLeaderUrl.json?leader_email=%@&url=%@",localEmail,urlToPublish];
NSURL *url = [[NSURL alloc] initWithScheme:@"http" host:host path:urlString];
Example of [NSURL initWithScheme]
NSString *host = @"example.host.com";
NSString *urlString = [NSString stringWithFormat:@"/SetLeaderUrl.json?leader_email=%@&url=%@",localEmail,urlToPublish];
NSURL *url = [[NSURL alloc] initWithScheme:@"http" host:host path:urlString];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *jsonString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];