priore

Convert URL to a Tiny URL

Apr 23rd, 2015
1,436
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. - (NSURL*)tinyURL:(NSURL*)originalURL
  2. {
  3.     NSString *origUrl = [originalURL absoluteString];
  4.     NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://tinyurl.com/api-create.php?url=%@", [origUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
  5.     NSURLRequest *request = [ NSURLRequest requestWithURL:url
  6.                                               cachePolicy:NSURLRequestReloadIgnoringCacheData
  7.                                           timeoutInterval:10.0];
  8.     NSError *error;
  9.     NSURLResponse *response;
  10.     NSData *myUrlData = [ NSURLConnection sendSynchronousRequest:request
  11.                                                returningResponse:&response
  12.                                                            error:&error];
  13.     NSString *myTinyUrl = [[NSString alloc] initWithData:myUrlData encoding:NSUTF8StringEncoding];
  14.     return [NSURL URLWithString:myTinyUrl];
  15. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×