iOS开发应用里Twitter使用


  本文标签:iOS开发 Twitter

  iOS开发应用里Twitter使用是本文要介绍的内容,Twitter现在欧美地区极其火爆,如果各位开发者想在应用中增加 Twitter 功能,可以看一下许靖昕先生在博客中分享的代码  。

  1. - (void) postToTwitter  
  2. {  
  3.   // Since this will be launched in a separate thread, we need  
  4.   // an autorelease pool  
  5.   NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];  
  6.    
  7.   NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:  
  8.     [NSURL URLWithString:@"http://TWITTER_ACCOUNT:PASSWORD@twitter.com/statuses/update.xml"]   
  9.     cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0];  
  10.    
  11.   // The text to post  
  12.   NSString *msg = @"testing";  
  13.    
  14.   // Set the HTTP request method  
  15.   [request setHTTPMethod:@"POST"];  
  16.    
  17.   [request setHTTPBody:[[NSString stringWithFormat:@"status=%@", msg]   
  18.     dataUsingEncoding:NSASCIIStringEncoding]];  
  19.    
  20.   NSURLResponse *response;  
  21.   NSError *error;  
  22.    
  23.   if ([NSURLConnection sendSynchronousRequest:request   
  24.       returningResponse:&response error:&error] != nil)  
  25.     NSLog(@"Posted to Twitter successfully.");  
  26.   else   
  27.     NSLog(@"Error posting to Twitter.");   
  28.    
  29.   // Release pool  
  30.   [pool release];   
  31. }    
  32.  
  33. [NSThread detachNewThreadSelector:@selector(postToTwitter)  
  34.    toTarget:self withObject:nil]; 

  小结:iOS开发应用里Twitter使用的内容介绍完了,希望通过本文对你有所帮助!