目前我有找到三個
最基本最簡單的為http://tinyurl.com/
做法很簡單
NSString *link = [NSString stringWithFormat:@"http://tw.yahoo.com/"];
NSURL *url = [NSURL URLWithString: [NSString stringWithFormat:@"http://tinyurl.com/api-create.php?url=%@", link]];
NSString *link_shorten = [NSString stringWithContentsOfURL:url encoding:NSASCIIStringEncoding error:nil];
NSLog(@"link_shorten is %@",link_shorten);
再來是google的服務
請上git下載原作者開源碼
用法
GSUrl *url = [[GSUrl alloc] initWithString:@"http://tw.yahoo.com/"];
NSLog(@"[url shorten] is %@",[url shorten]);
好處是可以再解析短網址還原長網址內容
# GSUrl
Google URL Shortener in Objective-C
I create this class for my studies in Objective-C
## Usage
GSUrl *url = [[GSUrl alloc] initWithString:@"www.someurlhere.com"];
[url shorten]; // => http://goo.gl/aGf9V
## Json
I use [json-framework]("http://stig.github.com/json-framework") for parser.
## TODO
- Expand a short URL
- Look up a short URL's analytics
- Look up a user's history
最最最複雜的是
用法
MKBitlyHelper *bitlyHelper = [[MKBitlyHelper alloc] initWithLoginName:@"yourlogin" andAPIKey:@"yourapi"];
NSString *shortURL = [bitlyHelper shortenURL:@"http://mugunthkumar.com"];
NSString *longURL = [bitlyHelper expandURL:shortURL];
因為本人英文不好所以也沒去申請網頁申請
bit.ly的服務如果有人知道如何申請
請告訴我詳細步驟謝謝
沒有留言:
張貼留言