Social Framework Twitter With iOS7

Xcode5 and iOS7 having Twitter natively incorporated in iOS7 with Social Framework. All user can login by Twitter Account and Social Framework will stored data on device. In this tutorial you will see how to use Social Framework with Twitter by your iOS7 Application.



First create new Project in "Single View Application" and create a name "MySocial".



Goto MainStoryBoard Drag UIButton to ViewController as follows with name "Twitter Share" and "Facebook Share".


Open header file (Viewcontoller.h) and Create Action Name "ShareTwitter" When you are done this step, your header file should like this code below:

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
- (IBAction)ShareTwiiter:(id)sender;


@end

Open ViewController.m file your will see the code like this:

- (IBAction)ShareTwiiter:(id)sender {

}

 Click on "Build Phase" Tab, find the "Link Binary with Libraries" section and click on "+" button.


Add "Social Framework":



Go back to edit ViewController.m file on header position add #import<Social/Social.h> in to the header like this:

#import "ViewController.h"
#import <Social/Social.h>
@interface ViewController ()

@end

Add a new code on ShareTwitter() method with:

- (IBAction)ShareTwiiter:(id)sender {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
SLComposeViewController *tweetSheet = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:@"ทดสอบการ Tweet จาก แอพพลิเคชัน iOS ที่ทำเอง];
[self presentViewController:tweetSheet animated:YES completion:nil];
}

 }

Run your application (Before Running this app your might be login your Twitter Account in Setting on Simulator:




 It's Done!



Read more tutorial in Thailand iOS Developer Community

Comments

Post a Comment