Changes

Integrating Twitter into iPhone iOS 5 Applications

11 bytes added, 23:01, 28 October 2011
no edit summary
<table border="0" cellspacing="0" width="100%">
<tr>
<td width="20%">[[Recording Audio on an iPhone with AVAudioRecorder|Previous]]<td align="center">[[iPhone iOS 5 Development Essentials|Table of Contents]]<td width="20%" align="right">[[An Example iPhone iOS 5 TWTeetComposeViewController TWTweetComposeViewController Twitter Application|Next]]</td>
<tr>
<td width="20%">Recording Audio on an iPhone with AVAudioRecorder<td align="center"><td width="20%" align="right">An Example iPhone iOS 5 TWTeetComposeViewController TWTweetComposeViewController Twitter Application</td>
</table>
<hr>
When using the TWRequest class to construct Twitter API requests it will be necessary to use the Accounts framework to identify and request permission to use Twitter accounts in an application. When using the TWTeetComposeViewControllerTWTweetComposeViewController, however, the account handling is performed automatically by the class.
== The TWTeetComposeViewController TWTweetComposeViewController Class ==
As previously discussed, the TWTeetComposeViewController TWTweetComposeViewController class presents the user with a screen that can be used to send a Twitter message. Figure 54-2 provides an illustration of the class in action within an iPhone application:
[[Image:iphone_ios_5_TWTeetComposeViewControlleriphone_ios_5_TWTweetComposeViewController.jpg|The iPhone iOS 5 TWTweetComposeViewController panel]]
Figure 54-2
In order to use the TWTeetComposeViewController TWTweetComposeViewController class a number of steps should be performed in sequence. Firstly, the application may optionally check to verify whether a Twitter message can be sent using the device. This essentially equates to checking if a Twitter account has been configured on the device and is achieved using the canSendTweet class method as follows:
<pre>
The next step is to create an instance of the TWTweetComposeViewController class and supply an optional completion handler to be called when the composer screen is either cancelled by the user or used to send a message. Next, a range of methods may be called on the instance to initialize the object with the content of the message including the initial text of the message, an image attachment and a URL:
* '''setInitialText:''' - Sets the initial text of the Twitter message on the TWTeetComposeViewController TWTweetComposeViewController instance.
* '''addImage:''' - Adds image files as attachments to the message. The class automatically handles URL shortening and resizing of the image for Twitter image hosting compatibility.
== Summary ==
iOS 5 introduced both the Twitter and Accounts frameworks both of which may be used to integrate Twitter functionality into iOS 5 applications. For more complex requirements the TWRequest class may be used in conjunction with the Accounts framework to access Twitter accounts and construct and submit Twitter API HTTP requests. An alternative and simpler approach that will meet the needs of most application developers involves the use of the TWTweetComposeViewController class. This chapter provided an overview of this class and the steps necessary to deploy it in applications. The next chapter, entitled [[An Example iPhone iOS 5 TWTeetComposeViewController TWTweetComposeViewController Twitter Application]] will work through the development of an example application using the TWTweetComposeViewContrioller class to implement basic Twitter functionality.
<table border="0" cellspacing="0" width="100%">
<tr>
<td width="20%">[[Recording Audio on an iPhone with AVAudioRecorder|Previous]]<td align="center">[[iPhone iOS 5 Development Essentials|Table of Contents]]<td width="20%" align="right">[[An Example iPhone iOS 5 TWTeetComposeViewController TWTweetComposeViewController Twitter Application|Next]]</td>
<tr>
<td width="20%">Recording Audio on an iPhone with AVAudioRecorder<td align="center"><td width="20%" align="right">An Example iPhone iOS 5 TWTeetComposeViewController TWTweetComposeViewController Twitter Application</td>
</table>