Tweets has been incorporated in iOS 5.0 and Facebook or myspace has been incorporated in iOS 6.0. Our guide concentrates on using the sessions offered by The apple company and the implementation objectives for Tweets and Facebook or myspace are iOS 5.0 and iOS 6.0 respectively.
Step 2. Select your venture computer file, then select objectives and then add Public.framework and Records.framework in choose frameworks.
Step 3. Add two control buttons known as facebookPost and twitterPost and build ibActions for them.
Step 4. Upgrade ViewController.h as follows −
Steps Involved
Step 1. Make a easy view-based program.Step 2. Select your venture computer file, then select objectives and then add Public.framework and Records.framework in choose frameworks.
Step 3. Add two control buttons known as facebookPost and twitterPost and build ibActions for them.
Step 4. Upgrade ViewController.h as follows −
import <Social/Social.h> #import <Accounts/Accounts.h> #import <UIKit/UIKit.h> @interface ViewController : UIViewController -(IBAction)twitterPost:(id)sender; -(IBAction)facebookPost:(id)sender; @end
Step 5. Update ViewController.m as follows −
#import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(IBAction)facebookPost:(id)sender{ SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook]; SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){ if (result == SLComposeViewControllerResultCancelled) { NSLog(@"Cancelled"); } else { NSLog(@"Done"); } [controller dismissViewControllerAnimated:YES completion:nil]; }; controller.completionHandler =myBlock; //Adding the Text to the facebook post value from iOS [controller setInitialText:@"My test post"]; //Adding the URL to the facebook post value from iOS [controller addURL:[NSURL URLWithString:@"http://www.test.com"]]; //Adding the Text to the facebook post value from iOS [self presentViewController:controller animated:YES completion:nil]; } -(IBAction)twitterPost:(id)sender{ SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter]; [tweetSheet setInitialText:@"My test tweet"]; [self presentModalViewController:tweetSheet animated:YES]; } @end
Output
When we run the program and just click facebookPost, we will get the following outcome −
When we just click twitterPost, we will get the following outcome −
1 comments :
Write commentsGood article,keep sharing more posts with us.
Replythank you...
ios online course
Emoticon Emoticon