iOS应用程序 Twitter开发代码是本文要介绍的内容,先来了解一下Twitter,它是国外的一个社交网络及微博客服务的网站。它利用无线网络,有线网络,通信技术,进行即时通讯,是微博客的典型应用。
Twitter允许用户将自己的***动态和想法以短信形式发送给手机和个性化网站群,而不仅仅是发送给个人。2006年,博客技术先驱blogger.com创始人埃文·威廉姆斯(Evan Williams)创建的新兴公司Obvious推出了大围脖服务。在最初阶段,这项服务只是用于向好友的手机发送文本信息。2006年底,Obvious对服务进行了升级,用户无需输入自己的手机号码,而可以通过即时信息服务和个性化Twitter网站接收和发送信息。
Twitter 现在欧美地区极其火爆,如果各位开发者想在应用中增加 Twitter 功能,可以看一下许靖昕先生在博客中分享的代码。
代码地址:http://blog.csdn.net/cloudhsu/article/details/6048626
- - (void) postToTwitter
- {
- // Since this will be launched in a separate thread, we need
- // an autorelease pool
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:
- [NSURL URLWithString:@"http://TWITTER_ACCOUNT:PASSWORD@twitter.com/statuses/update.xml"]
- cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0];
- // The text to post
- NSString *msg = @"testing";
- // Set the HTTP request method
- [request setHTTPMethod:@"POST"];
- [request setHTTPBody:[[NSString stringWithFormat:@"status=%@", msg]
- dataUsingEncoding:NSASCIIStringEncoding]];
- NSURLResponse *response;
- NSError *error;
- if ([NSURLConnection sendSynchronousRequest:request
- returningResponse:&response error:&error] != nil)
- NSLog(@"Posted to Twitter successfully.");
- else
- NSLog(@"Error posting to Twitter.");
- // Release pool
- [pool release];
- }
- [NSThread detachNewThreadSelector:@selector(postToTwitter)
- toTarget:self withObject:nil];
- - (void) postToTwitter
- {
- // Since this will be launched in a separate thread, we need
- // an autorelease pool
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:
- [NSURL URLWithString:@"http://TWITTER_ACCOUNT:PASSWORD@twitter.com/statuses/update.xml"]
- cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0];
- // The text to post
- NSString *msg = @"testing";
- // Set the HTTP request method
- [request setHTTPMethod:@"POST"];
- [request setHTTPBody:[[NSString stringWithFormat:@"status=%@", msg]
- dataUsingEncoding:NSASCIIStringEncoding]];
- NSURLResponse *response;
- NSError *error;
- if ([NSURLConnection sendSynchronousRequest:request
- returningResponse:&response error:&error] != nil)
- NSLog(@"Posted to Twitter successfully.");
- else
- NSLog(@"Error posting to Twitter.");
- // Release pool
- [pool release];
- }
- [NSThread detachNewThreadSelector:@selector(postToTwitter)
- toTarget:self withObject:nil];
小结:iOS应用程序 Twitter开发代码的内容介绍完了,希望本文对你有所帮助。
本文来自:http://www.cocoachina.com/iphonedev/sdk/2010/1202/2431.html