Objective-C Tips & Trick - Prioregroup.com
[Objective-C] Convert URL to a Tiny URL
       
back

- (NSURL*)tinyURL:(NSURL*)originalURL
{
    NSString *origUrl = [originalURL absoluteString];
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://tinyurl.com/api-create.php?url=%@", [origUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
    NSURLRequest *request = [ NSURLRequest requestWithURL:url
                                              cachePolicy:NSURLRequestReloadIgnoringCacheData
                                          timeoutInterval:10.0];
    NSError *error;
    NSURLResponse *response;
    NSData *myUrlData = [ NSURLConnection sendSynchronousRequest:request
                                               returningResponse:&response
                                                           error:&error];
    NSString *myTinyUrl = [[NSString alloc] initWithData:myUrlData encoding:NSUTF8StringEncoding];
    return [NSURL URLWithString:myTinyUrl];
}






Copyright © 1996-2018 Centro Studi Informatica di Danilo Priore. All rights reserved. P.I.10149810581.
prioregroup.com