0

According to the official FAQ from ver.2 to customize your text/content depending on what sharer was selected by the user, you need:

  1. subclass from SHKActionSheet and override dismissWithClickedButtonIndex
  2. set your new subclass name in configurator (return it in (Class)SHKActionSheetSubclass;).

It doesn't work for me. But even more: I put

NSLog(@"%@", NSStringFromSelector(_cmd));

in (Class)SHKActionSheetSubclass to see if it's even got called. And it's NOT ;(( So ShareKit doesn't care about this config option... Has anybody worked with this before?

thank you!

UPD1: I put some code here. Here's how my subclass ITPShareKitActionSheet looks like. According to the docs I need to override dismissWithClickedButtonIndex:animated:, but to track if my class gets called I also override the actionSheetForItem::

+ (ITPShareKitActionSheet *)actionSheetForItem:(SHKItem *)item
{
    NSLog(@"%@", NSStringFromSelector(_cmd));

    ITPShareKitActionSheet *as = (ITPShareKitActionSheet *)[super actionSheetForItem:item];

    return as;
}

- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animate
{
    NSLog(@"%@", NSStringFromSelector(_cmd));

    NSString *sharersName = [self buttonTitleAtIndex:buttonIndex];
    [self changeItemForService:sharersName];
    [super dismissWithClickedButtonIndex:buttonIndex animated:animate];
}

And here's what I do in code to create an action sheet when user presses 'Share' button:

- (IBAction)shareButtonPressed:(id)sender
{
    // Create the item to share
    SHKItem *item = [SHKItem text:@"test share text"];

    // Get the ShareKit action sheet
    ITPShareKitActionSheet *actionSheet = [ITPShareKitActionSheet actionSheetForItem:item];

    // Display the action sheet
    [actionSheet showInView:self.view]; // showFromToolbar:self.navigationController.toolbar];
}

When I run this code, press 'Share' button and select any sharer I expect to get two lines in log:

  1. actionSheetForItem: - custom action sheet got created
  2. dismissWithClickedButtonIndex:animated: - custom mechanics to process action sheet's pressed button got called.

But for some reason I get only the first line logged.

Arseniy
  • 487
  • 4
  • 14

2 Answers2

0

edit: by far the best way to achieve this is to use SHKShareItemDelegate. More info is in ShareKit's FAQ.

Vilém Kurz
  • 3,401
  • 2
  • 34
  • 43
  • Thanks for taking time to answer during New Year time ;)) Please check the upd1 in my answer. As you can see from my code I do subclass from SHKActionSheet (in fact I just copied it from the docs), but it doesn't work still :( – Arseniy Jan 03 '13 at 09:19
0

I was having the same issues but I've suddenly got it to call my Subclass successfully.

Firstly My Configurator is setup as so:

-(Class) SHKActionSheetSubclass{
    return NSClassFromString(@"TBRSHKActionSheet");
}

Now My Subclass: .h File

    #import "SHKActionSheet.h"
    @interface TBRSHKActionSheet : SHKActionSheet

    @end

.m implementation override:

#import "TBRSHKActionSheet.h"
#import "SHKActionSheet.h"
#import "SHKShareMenu.h"
#import "SHK.h"
#import "SHKConfiguration.h"
#import "SHKSharer.h"
#import "SHKShareItemDelegate.h"

@implementation TBRSHKActionSheet

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
if (self) {
    // Initialization code
}
return self;
}

    + (SHKActionSheet *)actionSheetForItem:(SHKItem *)i
{
        NSLog(@"%@", NSStringFromSelector(_cmd));

    SHKActionSheet *as = [self actionSheetForType:i.shareType];
    as.item = i;
    return as;
}

     - (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated
{
   NSInteger numberOfSharers = (NSInteger) [sharers count];

    // Sharers
    if (buttonIndex >= 0 && buttonIndex < numberOfSharers)
    {
        bool doShare = YES;
        SHKSharer* sharer = [[NSClassFromString([sharers objectAtIndex:buttonIndex]) alloc] init];
        [sharer loadItem:item];
        if (shareDelegate != nil && [shareDelegate respondsToSelector:@selector(aboutToShareItem:withSharer:)])
        {
            doShare = [shareDelegate aboutToShareItem:item withSharer:sharer];
        }
        if(doShare)
            [sharer share];
    }

// More
else if ([SHKCONFIG(showActionSheetMoreButton) boolValue] && buttonIndex == numberOfSharers)
{
    SHKShareMenu *shareMenu = [[SHKCONFIG(SHKShareMenuSubclass) alloc] initWithStyle:UITableViewStyleGrouped];
    shareMenu.shareDelegate = shareDelegate;
    shareMenu.item = item;
    [[SHK currentHelper] showViewController:shareMenu];

}

[super dismissWithClickedButtonIndex:buttonIndex animated:animated];
}

Finally on my implementation file I've not modified the call to SHKActionSheet as Vilem has suggested because of some dependancies that seemed to cause conflicts for me.

So this is my caller (straight from tutorial):

            NSURL *url = [NSURL URLWithString:@"http://getsharekit.com"];
    SHKItem *item = [SHKItem URL:url title:@"ShareKit is Awesome!" contentType:SHKURLContentTypeWebpage];

    // Get the ShareKit action sheet

    SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];

    // ShareKit detects top view controller (the one intended to present ShareKit UI) automatically,
    // but sometimes it may not find one. To be safe, set it explicitly
    [SHK setRootViewController:self];

    // Display the action sheet
    [actionSheet showFromToolbar:self.navigationController.toolbar];

This Calls no problems for me.

AMIC MING
  • 6,306
  • 6
  • 46
  • 62