Sharekit2.0:我如何直接分享到Facebook和Twitter,而不是通过UIActionSheet?

时间:2012-12-01 09:35:32

标签: ios facebook twitter share sharekit

我正在项目中使用最新的Sharekit2.0。

附上了两个按钮(“在Facebook上获得投票”和“在Twitter上分享”),因此我不需要UIActionSheet来提示。我如何直接分别向facebook和twitter分享文字信息。

由于

2 个答案:

答案 0 :(得分:1)

请你试试以下内容:

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

然后为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];    

}

请给我一个反馈,谢谢。

答案 1 :(得分:0)

另一种方式:

#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];   

}

但是你需要在shk.m中更改函数favoriteSharersForType以仅显示twitter和facebook选项。

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];
    }

并更改DefaultSHKConfigurator.m中的变量defaultFavoriteURLSharers,以便仅显示facebook和twitter:

- (NSArray*)defaultFavoriteURLSharers {
    return [NSArray arrayWithObjects:@"SHKFacebook",@"SHKTwitter", nil];
}