iOS開發應用里Twitter使用
作者:佚名
本文介紹的是iOS開發應用里Twitter使用方法,很詳細的介紹了Twitter方法的使用,先來看內容詳解。
iOS開發應用里Twitter使用是本文要介紹的內容,Twitter現在歐美地區極其火爆,如果各位開發者想在應用中增加 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];
小結:iOS開發應用里Twitter使用的內容介紹完了,希望通過本文對你有所幫助!
責任編輯:zhaolei
來源:
互聯網