Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone Twitter SDK integration problems with iOS 5 devices

I have successfully integrated Twitter Sharekit with my iPad application source. When I tested the app on simulator and iPad 1 with iOS 4.X it was working perfect and tweets were successfully posted. But the same package if I install on iPad 2 with iOS 5, tweet can't be posted and it just shows Authorize app message continuously. I can't find any other issue with this.

like image 950
Paresh Thakor Avatar asked Feb 03 '12 06:02

Paresh Thakor


1 Answers

Use the native Twitter available with the iOS 5 to integrate twitter. On one hand the UI is fabulous and on the other you will not have any problem using SharKit. Though I must tell you ShareKit is the best option for iOS versions below 5.

To use native Twitter integration do the following. Add these statements to the your class after including the necessary frameworks

#if defined(__IPHONE_5_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_5_0
#import <Twitter/Twitter.h>
#import <Accounts/Accounts.h>
#endif

Please note that when adding the Framework for Twitter and Accounts make sure they are set as optional.

And then in you share method use the lines

- (void)shareOnTwitter {
Class TWTweetComposeViewControllerClass = NSClassFromString(@"TWTweetComposeViewController");

    if (TWTweetComposeViewControllerClass != nil) {
        if([TWTweetComposeViewControllerClass respondsToSelector:@selector(canSendTweet)]) {
            UIViewController *twitterViewController = [[TWTweetComposeViewControllerClass alloc] init];

            [twitterViewController performSelector:@selector(setInitialText:) 
                                        withObject:twitterText];
            [twitterViewController performSelector:@selector(addURL:) 
                                        withObject:[NSURL URLWithString:url]];

            [twitterViewController performSelector:@selector(addImage:) 
                                        withObject:urImage];
            [self presentModalViewController:twitterViewController animated:YES];
            [twitterViewController release];
        }
else {
// Use ShareKit for previous versions of iOS
} 
}

Hope this helps.

like image 157
visakh7 Avatar answered Oct 06 '22 05:10

visakh7