Archive | iOS RSS for this section

iOS 5 Twitter Framework Integration

One of the new features in iOS 5 that will save you a lot of time is the Twitter integration.

The first thing you need to do is add the Twitter framework to your project.

Then include the Twitter header file in your header

#import Twitter/Twitter.h

Next you need to create a TWTweetComposeViewController and set the text/link/image that you want to share.

TWTweetComposeViewController *tweetSheet = [[TWTweetComposeViewController alloc] init ];
[tweetSheet setInitialText:@"Tweet Text"]];
 
[tweetSheet addImage:[UIImage imageNamed:@"yourimage"]];
 
[tweetSheet addURL:[NSURL URLWithString:@"http://www.jamie.co.za"]];
 
tweetSheet.completionHandler = ^(TWTweetComposeViewControllerResult result) {
        [self dismissModalViewControllerAnimated:YES];
    };
 
[self presentModalViewController:tweetSheet animated:YES];

Thats all there is to it, simple and quick.

There is also a canSendTweet function you can call to detect if the user has a twitter account setup on the device. The completionHandler will be called once the tweet has been sent.

Simultaneous Gesture Recognizers

To recognize 2 gestures simultaneously, such as to enable panning and rotating at the same time, there is a method called gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: in the UIGestureRecognizerDelegate protocol. By default it returns NO so implement the method and return YES.

 

- (BOOL) gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
 
    return YES;
 
}