When the user posts to FB or Twitter I want to know that the share completed, or the view was dismissed with an x.
Does anyone know if there is a delegate method built into ShareKit or if I have to write my own methods into it?
Right now I'm using the shar开发者_开发知识库ers directly, but I may switch to use the sharekit popup. I'm just using the two line code:
SHKItem *item = [SHKItem text:someText];
[SHKFacebook shareItem:item];
I faced your problem and came out with a solution, perhaps not the prettiest one, but it does solve the problem. There is a delagate called SHKSharerDelegate, which can be used with sharers for this purpouse, so if you are calling sharers directly from your code (no action sheet), then you should do something like this:
NSString* mySharerClassName = @"SHKFacebook";
SHKSharer* classItem = (SHKSharer*)[[NSClassFromString(mySharerClassName) alloc] init];
Class sharerClass = [classItem class];
if ( [sharerClass canShare] ){
[classItem performSelector: @selector(setItem:) withObject: item];
//Assuming that the class where this code is conforms to the SHKSharerDelegate protocol
[classItem performSelector: @selector(setShareDelegate:) withObject: self];
[classItem performSelector: @selector(send)];
}
If you have to use the ActionSheet, it gets a little trickier, mostly because there is no support for it, just go to the ActionSheet header file (ShareKit/UI/SHKActionSheet.h) and add a delegate property:
@property (nonatomic, retain) id sharerDelegate;
Notice that is not id<SHKSharerDelegate>
, try doing that and you'll experience a whole lot of pain. That's why I said that is not the prettiest one. Once you added and synthetized the property, look for this method:
- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated
And where it says
id sharer = [sharers objectAtIndex:buttonIndex];
[NSClassFromString(sharer) performSelector:@selector(shareItem:) withObject:item];
Change it for
id sharer = [sharers objectAtIndex:buttonIndex];
if ( sharerDelegate == nil ){
[NSClassFromString(sharer) performSelector:@selector(shareItem:) withObject:item];
}else{
SHKSharer* classItem = [[NSClassFromString(sharer) alloc] init];
[classItem performSelector: @selector(setItem:) withObject: item];
[classItem performSelector: @selector(setShareDelegate:) withObject: sharerDelegate];
[classItem performSelector: @selector(send)];
}
If you are more interested in this, I'll try to make a blog post soon and edit the answer to reference it. Hope I can still help somebody!
精彩评论