iPhone/iOS - How to use "ShareKit" to post only to Facebook or only to Twitter

18,292

Solution 1

Update:

Since this answer is still popular, I just wanted to add that with iOS 5 & iOS 6, there is much less need for Sharekit. A lot of popular sharing options are now built into the OS. That being said, this answer is still valid for the sharing services not built into the device, or if your simply more comfortable with Sharekit.


I'll show you how to do it for Facebook, Twitter is exactly the same, just change all the instances of Facebook to Twitter

First, #import "SHKFacebook.h" then in your button's target method, put the following:

SHKItem *item;    //This creates the Sharekit Item
NSURL *url = [NSURL URLWithString:@"http://itunes.apple.com/us/app/...?mt=8"];

The NSURL should be a link to your app on the app store. That way if someone sees a post your app made on Facebook, and they click it, they will be directed to the store so they can download it. Strickly speaking, this is optional, but why wouldn't you try to get new downloads with this extra one line.

Now we need to set up the SHKItem as follows:

item = [SHKItem URL:url title:[NSString stringWithFormat:@"I'm playing someGame on my iPhone! My Highscore is %i, think you can beat it?", highScoreInt]];

Then set up the post like this:

item = [SHKItem URL:url title:@"Share Me!"];

The title parameter is NOT user customizable. Whatever you set here the user will not be able to change. They will have the opportunity to add their own text in addition to whatever you put there.

Finally show the item:

[SHKFacebook shareItem:item];

I hope this helps. As I said, just change the Facebooks in this post to Twitter. Let me know in a comment if you need more help.

Solution 2

Sharekit provides a generic sharing mechanism but also exposes individual services. For instance, if you were to share a URL on twitter, you could write the following code:

#import "ShareKit/Core/SHK.h"
#import "ShareKit/Sharers/Services/Twitter/SHKTwitter.h"

...

SHKItem *item = [SHKItem URL:url title:@"A title"];
[SHKTwitter shareItem:item];

This is all explained in the documentation, but don't fear exploring the header files of the individual services.

Share:
18,292
Satyam
Author by

Satyam

I'm an iOS Applications Architect.

Updated on June 06, 2022

Comments

  • Satyam
    Satyam almost 2 years

    In my iPhone app, I have two two buttons, labeled "Facebook" and "Twitter". I want to use the Sharekit framework which makes my sharing very simple. But as shown in the sample code of ShareKit, I can only show many sharing services, which I don't want to include. I want my "Facebook" button to only show the Facebook sharing service, and the same with Twitter. How can I modify ShareKit to work like that?

  • Chris Miles
    Chris Miles about 13 years
    This works great, except: the Facebook popup is not full screen. The views behind can still be interacted with (by tapping outside the Facebook popup border) which is not what users would expect (and not what we want). Have I missed a trick to force ShareKit to cover the existing views until the share request has completed?
  • Andrew
    Andrew about 13 years
    Your right that that background view is still active. In my app I always just left it active, but now that you mention it, the way you would disable touching is right after [SHKFacebook shareItem:item];, put this line: self.view.userInteractionEnabled = NO; The problem with that is you have to reenable sharing after the user finished. I haven't figured that out yet. I'll play with it and when I figure it out I'll update my answer above.
  • Chris Miles
    Chris Miles about 13 years
    Thanks. All we really need is a sharekit callback for when it has finished. However, the sharekit architecture doesn't make this trivial to add. If you figure out a solution that'd be great.
  • Nungster
    Nungster over 12 years
    Actually the popover is what users should expect and is in accordance of the Human Interface Guidelines. Anyway since this is a few months old, I am sure you've solved your issue.
  • Andrew
    Andrew over 12 years
    Yes, the popover is expected, but thats not what we were talking about. We were talking about disabling the background view while ShareKit was in use.
  • TamilKing
    TamilKing over 10 years
    @Andrew:Can you please tell how to share video in Twitter and Facebook using sharekit in ios