Skip to content
VilemKurz edited this page Dec 23, 2011 · 32 revisions

Q: I have added ShareKit to my project as submodule. How can I update it?

A: It is done in terminal. Assuming you are in your project' root directory, go to ShareKit directory:

cd Submodules/ShareKit

and download newest version of ShareKit:

git checkout development
git pull

It can happen, that also ShareKit is using newer version of its submodules, or some new are added. Make sure you download them too(*):

git submodule init    
git submodule update

Now you should tell your project, that ShareKit has been updated. Go to back your project root:

cd ../..

Your project git repo treats submodules as a reference to particular commit - now git updates the reference to actual ShareKit's commit:

git add Submodules/ShareKit
git commit -m 'ShareKit updated to the newest version'

(*) if you look at some of the submodules original repo on github (say facebook-ios-sdk), you may notice, that there is newer commit, than that you got with submodule update. This is because submodule update does checkout submodule to the commit specified in ShareKit, which may not be the latest in original submodule's repo.

Q: How can I customize ShareKit's action sheet? I do not need "more..." button and just need to always show some specific services only. Say Twitter, Facebook and Mail.

The best solution in this case is not to use ShareKit's action sheet at all. Create your own UIActionSheet with three buttons, and simply call ShareKit's convenience methods. The benefit is, that you do not change ShareKit's code, and can get its updates easily, if you add it as submodule (see installation). Another difference is, that original ShareKit's action sheet shows most recently used service on top - you may not need this. Example:

#import "SHK.h" //include the ShareKit's header at the top of your class

- (void)showShareActionSheet {    
     
    NSString *actionSheetTitle = [NSString stringWithFormat:NSLocalizedString(@"Share", nil)];
       
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:actionSheetTitle 
                                                             delegate:self 
                                                    cancelButtonTitle:nil
                                               destructiveButtonTitle:nil 
                                                    otherButtonTitles:@"ReadItLater", @"Twitter", nil];
    
    if ([MFMailComposeViewController canSendMail]) [actionSheet addButtonWithTitle:SHKLocalizedString(@"Email",nil)];
   
    [actionSheet addButtonWithTitle:NSLocalizedString(@"Cancel", @"Cancel button title")];
    actionSheet.cancelButtonIndex = actionSheet.numberOfButtons-1;
    
    actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
    
    // Display the action sheet
    [actionSheet showInView:self.view];
    [actionSheet release];
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    
    if (buttonIndex == actionSheet.cancelButtonIndex) return;
    
    NSDictionary *table = [[NSDictionary alloc] initWithObjectsAndKeys:@"SHKTwitter", @"Twitter", @"SHKFacebook", @"Facebook", @"SHKMail", SHKLocalizedString(@"Email", nil), nil];
    NSString *sharersName = [actionSheet buttonTitleAtIndex:buttonIndex];
    
    Class SharersClass = NSClassFromString([table objectForKey:sharersName]);
    [table release];
    
    // Create the item to share (in this example, a url)
    NSURL *url = [NSURL URLWithString:@"http://getsharekit.com"];
    SHKItem *item = [SHKItem URL:url title:@"ShareKit is Awesome!"];
        
    //call chosen sharer's convenience method. From this point on everything else is handled by ShareKit.
    [SharersClass performSelector:@selector(shareItem:) withObject:item];    
}

Q: Is it possible to make the shared item text or title slightly different for each sharer service?

A: YES. You can use SHKCustomActionSheet, and override

- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animate
{
    [self changeItemForService:buttonIndex];
    [super dismissWithClickedButtonIndex:buttonIndex animated:animated];  
}

- (void)changeItemForService:(NSInteger)buttonIndex
{
    if (buttonIndex == 1) {
        self.item.text = [self.item.text stringByAppendingString:@"suffix for service 1"];
    }
}

if you do this, it is recommended that you first copy SHKCustomActionSheet.m file outside of ShareKit submodule folder, and replace the file in the project instead of original ShareKit version. Then edit the "outside" file. This way it will not interfere with ShareKit submodule updates.

Q: I see ShareKit is translated to many languages. I have noticed, that in my app ShareKit speaks only languages my app speaks too.

You must set CFBundleAllowMixedLocalizations (or "Localized resources can be mixed” in XCode) to YES to allow frameworks to use extra languages.

Q: Is there any way to find username logged in each service?

Yes. There are two ways services interact with ShareKit - some store credentials in user's keychain, some do not. If they do not, ShareKit has to fetch and store available user info (e.g. username) after successful login in NSUserDefaults.

Facebook:

    NSDictionary *facebookUserInfo = [[NSUserDefaults standardUserDefaults] objectForKey:@"kSHKFacebookUserInfo"];
    NSString *fbUserName = [facebookUserInfo objectForKey:@"name"];

Twitter (pre iOS 5. In iOS 5 you have to ask account framework for available twitter users):

    NSDictionary *twitterUserInfo = [[NSUserDefaults standardUserDefaults] objectForKey:@"kSHKTwitterUserInfo"];
    NSString *twUserName = [twitterUserInfo objectForKey:@"screen_name"];

other sharers (sharer ID is a name of the sharer's class, e.g. SHKTumblr):

    [SHK getAuthValueForKey:@"username" forSharer:sharerId];

or some sharers (Tumblr, Google reader) use email as username:

    [SHK getAuthValueForKey:@"email" forSharer:sharerId];

Q: I would like to add a new sharer. Where to start?

All the necessary information is here.

Q: How can I enable thorough debug console output for ShareKit?

Uncomment line 33 in DefaultSHKConfigurator.h

Q: Can I enable auto–share for certain services?

Yes. Some sharers is auto-share disabled by default. The easiest way to enable auto–share is to create a class Category for each SHKSharer and override "- (BOOL)shouldAutoShare" method. For example:

// SHK+Autoshare.h
#import "SHKTwitter.h"
#import "SHKFacebook.h"

@interface SHKTwitter(Autoshare)
@end

@interface SHKFacebook(Autoshare)
@end
// SHK+Autoshare.m
#import "SHK+Autoshare.h"

@implementation SHKTwitter(Autoshare)
- (BOOL)shouldAutoShare { return YES; }
@end

@implementation SHKFacebook(Autoshare)
- (BOOL)shouldAutoShare { return YES; }
@end

Clone this wiki locally