我發現了幾個縮短URL
的例子。但是他們都沒有爲我工作。如果有人有工作實例,請分享。 我都試過了,如何縮短目標中的URL C
NSString *apiEndpoint = [NSString stringWithFormat:@"http://tinyurl.com/api-create.php?url=%@",strUrl];
NSString *shortURL = [NSString stringWithContentsOfURL:[NSURL URLWithString:apiEndpoint]
encoding:NSASCIIStringEncoding
error:nil];
NSLog(@"Long: %@ - Short: %@",strUrl,shortURL);
NSString *shortenedURL = [NSString stringWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://api.bit.ly/v3/shorten?login=%@&apikey=%@&longUrl=%@&format=txt", @"[email protected]", @"R_2db6e96aad348b8c993acf6ba80884c4", strUrl]] encoding:NSUTF8StringEncoding error:nil];
NSLog(@"Shoted url %@", [shortenedURL JSONValue]);
還第一粘貼此線以上我們的代碼strUrl = [strUrl stringByReplacingOccurrencesOfString:@ 「 」withString:@「」]; –