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开发代码的内容介绍完了,希望通过本文的学习对你有所帮助!