How to customize ShareKit actionsheet?
Asked Answered
B

7

14

I am using ShareKit (www.getsharekit.com) to share my URL's to Twitter and Facebook. I want to be able to remove all of the additional social network it points to, but am not sure where to edit?

Belgian answered 24/10, 2010 at 12:58 Comment(0)
A
14

From ShareKit/Core/SHK.m:

[SHK setFavorites: (NSArray *)favs forType:(SHKShareType)type]

+ (void)setFavorites:(NSArray *)favs forType:(SHKShareType)type
{
    [[NSUserDefaults standardUserDefaults] setObject:favs forKey:[NSString stringWithFormat:@"%@%i", SHK_FAVS_PREFIX_KEY, type]];
}

favs is like :

[NSArray arrayWithObjects:@"SHKTwitter",@"SHKFacebook",@"SHKReadItLater",nil]

type is SHKShareType:

typedef enum 
{
    SHKShareTypeUndefined,
    SHKShareTypeURL,
    SHKShareTypeText,
    SHKShareTypeImage,
    SHKShareTypeFile
} SHKShareType;
Asben answered 24/10, 2010 at 13:20 Comment(0)
T
49

in SHK.m find this method

+ (NSArray *)favoriteSharersForType:(SHKShareType)type

and change

switch (type) 
    {
        case SHKShareTypeURL:
            favoriteSharers = [NSArray arrayWithObjects:@"SHKTwitter",@"SHKFacebook",@"SHKReadItLater",nil];
            break;

        case SHKShareTypeImage:
            favoriteSharers = [NSArray arrayWithObjects:@"SHKTwitter",@"SHKFacebook",@"SHKReadItLater",nil];
            break;

        case SHKShareTypeText:
            favoriteSharers = [NSArray arrayWithObjects:@"SHKTwitter",@"SHKFacebook",@"SHKReadItLater",nil];
            break;

        case SHKShareTypeFile:
            favoriteSharers = [NSArray arrayWithObjects:@"SHKTwitter",@"SHKFacebook",@"SHKReadItLater",nil];
            break;

to the following for each instance of the switch statement:

favoriteSharers = [NSArray arrayWithObjects:@"SHKFacebook", nil];

or what ever other options you want to support (ie if you only want twitter and facebook add @"SHKTwitter", to the array)

that will eliminate the other options but the action sheet that displays the options wont reflect the change and it will still give the more option, which we also need to disable.

So to do that go to SHKActionSheet.m

in this method you can change the title from "Share" to something more specific (this part is optional) ie "Share with Facebook and Twitter"

+ (SHKActionSheet *)actionSheetForType:(SHKShareType)type

change

SHKActionSheet *as = [[SHKActionSheet alloc] initWithTitle:SHKLocalizedString(@"PUT YOUR NEW TITLE HERE")
                                                  delegate:self
                                         cancelButtonTitle:nil
                                    destructiveButtonTitle:nil
                                         otherButtonTitles:nil];
as.item = [[[SHKItem alloc] init] autorelease];
as.item.shareType = type;

than in that same method, delete this line

    // Add More button
[as addButtonWithTitle:SHKLocalizedString(@"More...")];

that will remove the more button but now the code will now confuse the more button with the cancel button, so to fix that, go to this method:

- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated

and delete the following else if statement

// More
else if (buttonIndex == sharers.count)
{
    SHKShareMenu *shareMenu = [[SHKCustomShareMenu alloc] initWithStyle:UITableViewStyleGrouped];
    shareMenu.item = item;
    [[SHK currentHelper] showViewController:shareMenu];
    [shareMenu release];
}

what this method is susposted to do is take the button that is normally the more button and open the more options. So by deleting it the code has no associated action with the cancel button so it just closes and release the action sheet, effectively creating a cancel button

Tresa answered 19/12, 2010 at 17:3 Comment(2)
Wish I could give you 10 upvotes for such a thorough explanation. This is exactly what I needed - thanks!Joris
What a great answer. Best thing I've seen on SO in a while... and by someone with low rep like me!Balkh
A
14

From ShareKit/Core/SHK.m:

[SHK setFavorites: (NSArray *)favs forType:(SHKShareType)type]

+ (void)setFavorites:(NSArray *)favs forType:(SHKShareType)type
{
    [[NSUserDefaults standardUserDefaults] setObject:favs forKey:[NSString stringWithFormat:@"%@%i", SHK_FAVS_PREFIX_KEY, type]];
}

favs is like :

[NSArray arrayWithObjects:@"SHKTwitter",@"SHKFacebook",@"SHKReadItLater",nil]

type is SHKShareType:

typedef enum 
{
    SHKShareTypeUndefined,
    SHKShareTypeURL,
    SHKShareTypeText,
    SHKShareTypeImage,
    SHKShareTypeFile
} SHKShareType;
Asben answered 24/10, 2010 at 13:20 Comment(0)
J
7

The new way to do this with latest version of ShareKit 2.0 is to overwrite the following methods in your SHKConfigurator (extending DefaultSHKConfigurator.m)

// SHKActionSheet settings
- (NSNumber*)showActionSheetMoreButton {
    return [NSNumber numberWithBool:true];// Setting this to true will show More... button in SHKActionSheet, setting to false will leave the button out.
}

/*
 Favorite Sharers
 ----------------
 These values are used to define the default favorite sharers appearing on ShareKit's action sheet.
 */
- (NSArray*)defaultFavoriteURLSharers {
    return [NSArray arrayWithObjects:@"SHKTwitter",@"SHKFacebook", @"SHKReadItLater", nil];
}
- (NSArray*)defaultFavoriteImageSharers {
    return [NSArray arrayWithObjects:@"SHKMail",@"SHKFacebook", @"SHKCopy", nil];
}
- (NSArray*)defaultFavoriteTextSharers {
    return [NSArray arrayWithObjects:@"SHKMail",@"SHKTwitter",@"SHKFacebook", nil];
}
Jorgensen answered 9/5, 2013 at 14:6 Comment(0)
D
2

See my answer on the other thread with more thorough explanation.

It is now easily configurable without changing ShareKit's code, if you use ShareKit 2.0

Basically, if you use only Facebook and Twitter, it is easier not to mess with ShareKit's code. You can easily create your own UIActionSheet with two buttons, and call ShareKit's convenience share methods.

Dolores answered 23/11, 2011 at 7:43 Comment(1)
wonder why down vote? With "mess with ShareKit's code" I mean to customize ShareKit's code in your app (hiding More button), when it is not necessary. This will earn you additional work, if you want to upgrade to newer version of ShareKit. You can achieve the same using ShareKit's sharers convenience methods directly with classic standard UIActionSheet.Rauch
C
2

For the unwanted services not to appear on the action sheet you can simply remove the respective sharer services classes from the project.

Go to project--> Sharers --> Services --> select the .h and .m files of the respective service and delete it.

For example Facebook option can be removed by deleting SHKFacebook.h and SHKFacebook.m.

Note: You will have to check the class import to avoid errors.

Circumstance answered 27/4, 2012 at 7:2 Comment(0)
P
0

Easiest way is to edit "SHKSharers.plist" and keep the services you need.

Proctor answered 24/8, 2014 at 21:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.