iOS应用开发之Twitter开发代码

移动开发 iOS
iOS应用开发中的Twitter开发代码是本文要介绍的内容,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. [NSThread detachNewThreadSelector:@selector(postToTwitter)  
  33.    toTarget:self withObject:nil]; 

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

责任编辑:zhaolei 来源: 互联网
相关推荐

2011-07-21 16:19:30

iOS Twitter

2011-08-08 13:26:48

iOS开发 Twitter

2011-08-02 11:30:41

iOS开发 邮件发送

2012-01-18 13:46:37

ARCiOS

2011-05-11 10:02:37

iOS

2014-07-23 13:17:53

iOSUITextField

2014-07-21 14:49:35

iOSUILabel

2014-09-26 09:49:48

SwiftObjective-C

2011-07-28 15:11:23

iOS Objective-

2021-01-26 19:13:15

iOS开发文本编辑器Twitter

2013-09-13 13:16:05

2011-07-08 14:58:16

iPhone Xcode iOS

2011-08-02 11:07:42

iOS开发 UIWebView

2017-02-15 09:25:36

iOS开发MQTT

2024-04-09 09:24:13

2012-02-13 13:45:04

MonoTouch.NETiOS应用

2011-08-17 14:20:21

IOS开发GraphicsCon

2011-07-26 11:08:23

iOS 录像 录音

2012-01-18 10:57:37

ARCiOS

2012-02-02 10:14:14

点赞
收藏

51CTO技术栈公众号