• Home
  • MAD
  • Concept Series
    • Software Design
    • Software Arch
    • GIT & Github
    • System Design
    • Cloud
    • Database Integration
    • Push Notification
    • API Integration
    • Cocoa PODS
  • DSA
  • Interview
  • Tips&Tricks
  • YT
  • Home
  • MAD
  • Concept Series
    • Software Design
    • Software Arch
    • GIT & Github
    • System Design
    • Cloud
    • Database Integration
    • Push Notification
    • API Integration
    • Cocoa PODS
  • DSA
  • Interview
  • Tips&Tricks
  • YT
  • #News
  • #APPS
  • #Events
    • #WWDC
    • #I/O
    • #Ignite
  • #Let’s Talk

MyCodeTips mycodetips-newlogocopy1

  • Home
  • MAD
  • Concept Series
    • Software Design
    • Software Arch
    • GIT & Github
    • System Design
    • Cloud
    • Database Integration
    • Push Notification
    • API Integration
    • Cocoa PODS
  • DSA
  • Interview
  • Tips&Tricks
  • YT
IOS

Facebook and Twitter Sharing in iOS application using Social Framework

Facebook and Twitter Sharing in iOS

If you are working on iOS app development, then these days, everyone prefers to implement the social network sharing features like Twitter and Facebook sharing. If implemented, then this will add value to your iOS app and boost its popularity with Facebook and Twitter sharing support.

Let’s start to learn how you can integrate Facebook and Twitter sharing using Social framework.

Create class named SocialSharingVC with XIB named SocialSharingView Add two buttons in SocialSharingView named btnFacebookSharing and btnTwitterSharing and also define action events for both buttons btnFacebookSharing_Clicked and btnTwitterSharing_Clicked.

The social framework is not included when you create the new xCode project. So add Social.framework in the project.
Below is the final code for the SocialSharingVC.h class.

#import <UIKit/UIKit.h>

@interface SocialSharingVC : UIViewController

- (IBAction)btnFacebookSharing_Clicked:(id)sender;
- (IBAction)btnTwitterSharing_Clicked:(id)sender;

@end

Now all the code that you have to write in your implementation class SocialSharingVC.m for facebook and Twitter sharing is as given below.

First import the Social.h file at very top of the class SocialSharingVC.m as we have to use SLComposeViewController which is a class provided by social framework.


#import <Social/Social.h>

(IBAction)btnTwitterSharing_Clicked:(id)sender {
 if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
 {
 SLComposeViewController *tweetSheetOBJ = [SLComposeViewController
 composeViewControllerForServiceType:SLServiceTypeTwitter];
 [tweetSheetOBJ setInitialText:@"Learn iOS programming at mycodetips.com"];
 [self presentViewController:tweetSheetOBJ animated:YES completion:nil];
 }
}

(IBAction)btnFacebookSharing_Clicked:(id)sender {
 if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
 SLComposeViewController *fbSheetOBJ = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
 
 [fbSheetOBJ setInitialText:@"First post from my iOS application in mycodetips"];
 [self presentViewController:fbSheetOBJ animated:YES completion:Nil];
 }
}

(IBAction)btnFacebookSharing_Clicked:(id)sender {
 if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
 SLComposeViewController * fbSheetOBJ = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
 
 [fbSheetOBJ setInitialText:@"Post from my iOS application"];
 [fbSheetOBJ addURL:[NSURL URLWithString:@"http://mycodetips.com"]]; 
 [fbSheetOBJ addImage:[UIImage imageNamed:@"my_image_to_share.png"]]; 
 [self presentViewController:fbSheetOBJ animated:YES completion:Nil]; } }
Liked it? Take a second to support Ranjan on Patreon!
become a patron button
  • Click to share on Reddit (Opens in new window)
  • Click to share on Facebook (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Tumblr (Opens in new window)
  • More
  • Click to share on Pocket (Opens in new window)
  • Click to share on Pinterest (Opens in new window)
Written by Ranjan - 1484 Views
AUTHOR
Ranjan

Namaste, My name is Ranjan, I am a graduate from NIT Rourkela. This website is basically about of what i learnt from my years of experience as a software engineer on software development specifically on mobile application development, design patterns/architectures, its changing scenarios, security, troubleshooting, tools, tips&tricks and many more.

Next Post
Previous Post

Support us

mycodetips
mycodetips

Follow us @ LinkedIn 2850+

Subscribe for updates

Join 8,213 other subscribers

Latest Posts

  • YT-Featured-solidprinciples
    SOLID Principles of Software Design
  • IOS 16 Features
    Latest features in IOS 16
  • r-language
    How can R language be used for data analysis?
  • wordpress-coding-blog
    Guide To WordPress Coding Standards
  • YT-Featured-Algorithm
    What is Algorithm?
  • Frameworks of IOS
    Frameworks of IOS – Part ( I )
  • NSFileManager or NSPathUtilities
    NSFileManager or NSPathUtilities in Objective-C
  • Passing data between view controllers in Objective-C
    Passing data between view controllers in Objective-C
  • structures-classes-enum
    Structures and Classes in swift !
  • control-system-swift
    Control Flow in Swift
whiteboard

Whiteboard(PRO)

whiteboard

Whiteboard(lite)

alphabets

Kids Alphabet

techlynk

Techlynk

techbyte

Do2Day

techbyte

Techbyte

  • #about
  • #myapps
  • #contact
  • #privacy
  • #Advertise
  • #myQuestions

Android Android Studio API APP Programming Apps blogging CSS DATABASE dsa Features HTML HTML5 installation Interview Questions IOS iPhone javascript Mac objective-c OS Programming quicktips SDK SEO SQL swift Tips & Tricks Tools UI Web Wordpress Xcode

  • SOLID Principles of Software Design
  • Latest features in IOS 16
  • How can R language be used for data analysis?
  • Guide To WordPress Coding Standards
  • What is Algorithm?

©mycodetips.com