iOS應(yīng)用開發(fā)之Twitter開發(fā)代碼
作者:佚名
iOS應(yīng)用開發(fā)中的Twitter開發(fā)代碼是本文要介紹的內(nèi)容,Twitter現(xiàn)在歐美地區(qū)極其火爆,先來看本文代碼。
iOS應(yīng)用開發(fā)中的Twitter開發(fā)代碼是本文要介紹的內(nèi)容,Twitter現(xiàn)在歐美地區(qū)極其火爆,如果各位開發(fā)者想在應(yīng)用中增加Twitter功能,可以看一下許靖昕先生在博客中分享的代碼。
- - (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];
小結(jié):iOS應(yīng)用開發(fā)之Twitter開發(fā)代碼的內(nèi)容介紹完了,希望通過本文的學(xué)習(xí)對你有所幫助!
責(zé)任編輯:zhaolei
來源:
互聯(lián)網(wǎng)