iOS應用程序 Twitter開發代碼
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