iPhone で URl を TinyURL にプログラムで変換したいと考えています。これを行う方法?
			
			2723 次
		
3 に答える
            5        
        
		
Tiny URL には、使用できるシンプルな API があります。非常にシンプルです。
このリクエストを URL とともに送信するだけです
http://tinyurl.com/api-create.php?url=http://yourURL.com/
リンクを含む小さな URL が返されます
編集: これは実際の例です。これは同期リクエストですが、時間がかかりすぎるとアプリが応答しなくなる可能性があります。
NSString *origUrl = @"http://stackoverflow.com";
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://tinyurl.com/api-create.php?url=%@", origUrl]]; 
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];
//do stuff with url
[myTinyUrl release];
    于 2011-04-19T12:55:14.177   に答える
    
    
            3        
        
		
これが役立つかもしれません: tiny url api
于 2011-04-19T12:59:13.657   に答える
    
    
            0        
        
		
方法は簡単で、ios7 で動作します
NSError *error
NSString *tinyURL =  [NSString stringWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://tinyurl.com/api-create.php?url=%@", YOUR-URL]]
                                                  encoding:NSASCIIStringEncoding error:&error];
// error handling here..
    于 2013-12-20T17:41:53.437   に答える