Thursday, September 11, 2014

Convert long URLs into short (Bitly format)

Short URLs can be created in two different ways : Bitly and TinyUrl.
I have implemented this using Bitly approach.

Include BitlyShortUrl.h and BitlyShortUrl.m file into your project [available on Github].

Now, #import "BitlyShortUrl.h" in header file where functionality is to be implemented.
Specify delegate “BitlyShortUrlDelegate” in interface of header file.

#pragma mark -
#pragma mark BitlyShortUrlDelegate Methods

- (void)BitlyShortUrlSucceededWithShortUrl:(NSString *)shortUrl{
  // Success in creating short URL
    NSLog(@"shortUrl : %@ ",shortUrl);  

- (void)BitlyShortUrlFailedWithError:(NSError *)error {
  // Failed in creating short URL

 BitlyShortUrl *ShortURL = [[BitlyShortUrl alloc] initWithDelegate:self];
 [ShortURL BitlyUrl:longURLValue];

No comments:

Post a Comment