2

I'm using the latest Sharekit2.0 on a project.

Two buttons are listed ("Get votes on Facebook" and "Share on twitter") as attached, so I don't need a UIActionSheet to prompt. How can I directly share text information to facebook and twitter respectively.

Thanks

LiangWang
  • 8,038
  • 8
  • 41
  • 54

2 Answers2

1

could you please try the following:

#import "SHK.h"
#import "SHKFacebook.h"
#import "SHKTwitter.h"

then for facebook

-(IBAction)forFacebook:(id)sender;{
    NSString *someText = @"This is a blurb of text I highlighted from a document.";
    SHKItem *item = [SHKItem text:someText];  

    [SHKFacebook shareItem:item];    

}

for twitter

-(IBAction)forTwitter:(id)sender;{
    NSString *someText = @"This is a blurb of text I highlighted from a document.";
    SHKItem *item = [SHKItem text:someText];  

    [SHKTwitter shareItem:item];    

}

please give me a feedback, thanks.

piam
  • 653
  • 6
  • 13
  • piam. I just found an exception when I execute on iPhone4S (iOS6), the execution message is shown(http://stackoverflow.com/questions/13716185/shkfacebook-shareitemitem-execution-exception). How can I fix it? I'm sure it OK on simulator with iOS4、5、6 – LiangWang Dec 05 '12 at 04:55
0

Another Way:

#import "SHK.h"

-(IBAction)forSharing:(id)sender{

    NSString *someText = @"This is a blurb of text I highlighted from a document.";
    SHKItem *item = [SHKItem text:someText]; 

    SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item]; 

    [actionSheet showFromToolbar:navigationController.toolbar];   

}

But you need to change the function favoriteSharersForType in shk.m to show only twitter and facebook options.

if (favoriteSharers == nil)
    {
        switch (type) 
        {
            case SHKShareTypeURL:
                favoriteSharers = SHKCONFIG(defaultFavoriteURLSharers);
                break;

            case SHKShareTypeImage:
                favoriteSharers = SHKCONFIG(defaultFavoriteImageSharers);
                break;

            case SHKShareTypeText:
                favoriteSharers = SHKCONFIG(defaultFavoriteTextSharers);
                break;

            case SHKShareTypeFile:
                favoriteSharers = SHKCONFIG(defaultFavoriteFileSharers);
                break;

            default:
                favoriteSharers = [NSArray array];
        }

        // Save defaults to prefs
        [self setFavorites:favoriteSharers forType:type];
    }

and change the variable defaultFavoriteURLSharers in DefaultSHKConfigurator.m to show only facebook and twitter like this:

- (NSArray*)defaultFavoriteURLSharers {
    return [NSArray arrayWithObjects:@"SHKFacebook",@"SHKTwitter", nil];
}
lakshmen
  • 28,346
  • 66
  • 178
  • 276