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

你。 提交于 2019-11-28 05:25:33
Andrew

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.

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.

I also had the same problem in one of my apps, and tried to force sharekit to do just that.

ShareKit isn't really made for it though, it's meant to be a provide a large range of sharing options - so even after modification, I found that it wasn't a very elegant or efficient solution.

It will save a bit of time, sure - but if you want a good looking, elegant solution I'd suggest integrating twitter and facebook yourself. It takes a bit of time, but you can define the behavior exactly as you want, and theme the interface to suit your app better.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!