Monday, February 25, 2013

Sharing your app via Facebook and Twitter using Social Framework

Hello Guyz, in this section i will be describing about how we can use new "Social Framework" for sharing our app(tweet+status) from our iOS apps. It's really easy to deal with but, we should keep in mind that Social framework is only available from iOS 6 and later . Here, we will be only focusing on how to share our app , along with how to tweet and post a status from our iOS app.



1. Add "Social.framework" in your project.
2. Include  #import <Social/Social.h> to your .h file
3. Now, in your sharing method :



  // First check whether social framework is available or not?
 if(NSClassFromString(@"SLComposeViewController")!= nil){ //if present
     SLComposeViewController *socialPostVC = [SLComposeViewController  
                                                   composeViewControllerForServiceType:SLServiceTypeFacebook]; // select your social media type
//Service type can be facebook or twitter  : SLServiceTypeFacebook,SLServiceTypeTwitter
   // include your initial message that will be pre-filled up in composer sheet
 [socialPostVC setInitialText:@"This is the text that appears in your popup field where you write status/tweets"];
 // adding image to the post/tweets
  [socialPostVC addImage:[UIImage imageNamed:@"testImg.png"]];
//Now attaching your app, provide iTuneStore download link of your app if you have already submitted earlier version or you can grab dummy url from web service where later on  you can edit that with  your ituneStore link when app is accepted. Else provide any web url link you wanted that describes your app more.
            [socialPostVC addURL:[NSURL URLWithString:@"yourApp's iTuneStore link"]];
            [self presentViewController: socialPostVC animated:YES completion:nil];
         }
 else { // if not present
                // show alert, device does not support this framework
                UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Error !" message:@"Sorry, This Feature is only available in iOS version 6.0 or later." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
                [alert show];
                [alert release];
          }

That's the end of Social Framework integration for sharing apps,tweets,status via Social Media.  If you want to support Twitter integration for iOS 5 then there is another framework called "Twitter.Framework" for iOS 5. Refer : http://iosameer.blogspot.com/2012/08/twitter-integration-on-ios-5-later.html

Final output :


3 comments:

  1. readings were really very good. I will bookmark this blog so that I could often visit this blog often to read the latest article from your blog. behind terimaksih awaited visit, .......


    By : developing mobile app indonesia | firzil.co.id

    ReplyDelete
  2. As we know that Android and Windows are making their platform attractive and user friendly on a daily basis and that is why Apple needs to match them in the race and keep on working with the trend. Apart from all these widget iOS8 feature, the most important customer need is that they want to see everything on their home screen and do not like to shuffle between various apps and notifications.

    ReplyDelete
  3. Ios 8 in not working SLServiceTypeFacebook

    ReplyDelete