Skip to content
This repository

Prerequisites

You'll need newest iOS SDK, and ShareKit supports iOS 6.0 devices and above.

Installation via Cocoapods

If you're new to Cocoapods watch this. To add ShareKit to your app, add pod "ShareKit" to your Podfile, and jump to Step 4. If you only want to add specific libraries, like Facebook you can use pod "ShareKit/Facebook" and repeat that for each library.

This method is much easier than the subproject way (steps 1-3) and is strongly recommended. However Buffer sharers is not supported yet.

Installation via Git submodule and Xcode subproject

Step 1: Get ShareKit files

Info for people, who do not use git yet: The process of getting ShareKit files is very simple and quick, if your project is a Git repo. If it is not, you can create one easily in terminal app entering git init in the root of your project directory. If you decide not to use git, you will have to download all ShareKit files + separately download each submodule, and put the files in corresponding subdirectory of ShareKit/Submodules.

In terminal navigate to the root of your project directory and run these commands (assuming your project is a git repo):

git submodule add git://github.com/ShareKit/ShareKit.git Submodules/ShareKit
git commit -m 'ShareKit added as submodule'

This creates new submodule, downloads the files to Submodules/ShareKit directory within your project and creates new commit with updated git repo settings.

Now navigate to the newly created ShareKit dir and download all submodules files

cd Submodules/ShareKit
git submodule update --init --recursive

Thanks to the fact that you added ShareKit as submodule, it is easy to keep it updated to the newest version. For information on how to update, see FAQ.

Step 2: Add ShareKit to your project

Add ShareKit as xCode subproject

Open your app's project in Xcode. Make sure, that ShareKit project itself is NOT opened in xCode.

Drag the ShareKit project file (ShareKit.xcodeproj) from Finder into your project navigator in xCode. Make sure it is a sub-item of your main project, sitting underneath your main project, not next to it.

drag ShareKit project file

Now make small adjustments in your project's app target:

  1. add ShareKit's targets as dependencies to your project's build phase: your project's app target - build phases - target dependencies add 2 new targets from ShareKit subproject: "Static Library" and "Resource Bundle" For XCode 4.5 if you do not see ShareKit's targets when adding depenedencies, quit and re-launch XCode. add ShareKit's targets

  2. add ShareKit's "libShareKit.a" to your project's Link Binary With Libraries build phase add ShareKit lib

  3. add ShareKit's "Resource Bundle" to your project's Copy Bundle Resources build phase: expand shareKit subproject - expand products - move "ShareKit.bundle" to Copy Bundle Resources build phase in your project's target add ShareKit resource bundle

  4. change your project's app target build settings:

    • User header search paths: set it RECURSIVELY to the directory where you put submodules in. If you followed our install wiki, it should be Submodules/ . Two asterisks are a sign, that you have checked Recursive option. user header search path

    • Other Linker Flags: -ObjC -all_load other linker flags

Add Apple Frameworks

Expand the 'Frameworks' group in your project's file list. Make sure you have the following frameworks:

  • SystemConfiguration.framework
  • Security.framework
  • MessageUI.framework
  • MobileCoreService.framework
  • CoreMedia.framework
  • AVFoundation.framework
  • CFNetwork.framework (for Flickr)
  • CoreLocation.framework (for Foursquare)
  • Twitter.framework (it is new in iOS 5, so if you deploy to older versions of iOS, mark it optional)
  • AdSupport.framework (mark as optional, new in ios6), Accounts.framework (mark as optional, new in ios5), libsqlite3.dylib (mark as optional, for Facebook)
  • Social.framework (mark as optional, new in ios6) for all services natively supported in iOS (currently Facebook, Twitter, SinaWeibo)
  • StoreKit.framework (mark as optional, new in iOS6), libxml2.dylib for Evernote
  • QuartzCore.framework for Dropbox
  • MediaPlayer.framework, AssetsLibrary.framework, CoreText.framework, CoreMotion.framework, AddressBook.framework for Google+
  • ImageIO.framework for PhotoAlbum action

If you are missing any frameworks, go to your app target - Build Phases - Link Binary With Libraries - add missing libraries by pressing small + in the left bottom corner of the Link Binary With Libraries section.

Add 3rd Party Frameworks

Open ShareKit/Frameworks in finder and drag all frameworks and bundles to the frameworks group in your project navigator. Make sure that "Copy items into destination group's folder (if needed)" is NOT checked + select your app's target in "add to targets" section so that it is linked with your app. In case you do granular install, drag only frameworks you need.

For Microsoft OneNote you have to add LiveSDK.framework also to Copy Bundle Resources build phase of your app's target

Add resources

Some 3rd party SDK's come with resources (nibs, graphics..). Due to the static lib nature of ShareKit you have to add them manually to your project. Drag the "Resources - ShareKit Library" group from ShareKit.xcodeproj to your project. add resources

Base SDK and Deployment Targets

If you aren't already, you'll want to make sure your base SDK is set to Latest iOS. You can still support older versions (back to 5.*) by setting your deployment target.

Step 3: Smoke Test

Build your project. If it won't build, try these troubleshooting steps.

Issue: "Undefined symbols for architecture armv7"

You probably forgot to add one of the frameworks listed above. For example, if you added Social.framework then you also need libsqlite3.dylib, Accounts.framework and AdSupport.framework as well. Do NOT try to solve this problem by removing the compiler linker flags since you are just setting yourself up for issues later on.

Issue: "error: no such file or directory:"

You may not have the submodules installed correctly. Compare the contents of ShareKit/Submodules with the list in ShareKit/.gitmodules. If the submodules aren't installed, you may have to go back and very carefully follow the instructions in Step 1.

Issue: "'OAuthConsumer/OAToken.h' file not found" (or similar)

If, up until now, you have been using a library that is already part of ShareKit (e.g., SBJSON, facebook-ios-sdk, Twitter+OAuth, et. al), you may need to remove references to those libraries. Don't forget to double check your Framework, Header, Library, and User Header Search Paths and remove any older, still-lingering references as well. (In your project and/or target settings, under "Build Settings", search for "Search Paths".)

The other way to solve this is to remove these libraries from ShareKit - see granular install. Granular install can also help you to prevent compiling sharers, which you do not use.

Step 4: Configuration

See the Configuration page.

Step 5: Calling ShareKit

Import the ShareKit Header

In any class where you call ShareKit, you'll need to include the ShareKit header at the top. At the top of your class you'll probably see other imports already. Add ShareKit to the list:

#import "ShareKit.h"

Add a Share Button

Share button screenshot

This section is subjective and entirely depends on how you design your app. It assumes you know how to create a button that performs an action. If you'd like more guidance, take a look a the example project (included in the ShareKit download). It has a separate example for sharing links, images, text, and files.

You need to add a way to allow the user to say 'hey, I want to share this!'. It is up to you where to place this button and even what it looks like. If your app has a UIToolbar or UINavigationBar, a common practice is adding a UIBarButtonItem with the UIBarButtonSystemItemAction system item style. This icon has become the standard for sharing amongst iOS apps.

An example may look like: [UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(share)];

Handling the Button Action

button action screenshot

After you've added a button and set a target action to call when it's pushed, it's finally time to call ShareKit.

A user's entry point into ShareKit is an actionsheet. This actionsheet displays the user's most used services and a more button for additional options.

The actionsheet will only display services that can respond to the item you want to share. So the first step is to create an object (SHKItem) that describes what you want to share (a url, image, text, or file). With that item, you create an actionsheet and display it to the user. Here are the 3 steps together. In this example we'll share a URL:

- (void)myButtonHandlerAction {

    // 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!" 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:navigationController.toolbar];
}

That's it! ShareKit will take over from there and handle everything else. This includes logging the user in to their selected service, allowing them to edit the share item, displaying activity indicators, and even sharing offline.

Note: How/Where you display the action sheet is up to you. On an iPad you may want to display this as a popover from your share button. For all possible options, take a look at the UIActionSheet documentation.

To see examples sharing other types of content (images, text, or files) see additional documentation at getsharekit.com or the example project included in the ShareKit download.

Step 6: Offline Sharing

If your app can be used without an internet connection, you should support offline sharing. Luckily, this means only adding one additional line of code.

Most ShareKit services support offline sharing. This means when a user shares something while they are disconnected, ShareKit will store it and wait to send until they are connected again.

You just need to tell ShareKit when to retry these offline items. A good time to do this is when the app is opened. Simply add this line when you want ShareKit to try resending the items:

[SHK flushOfflineQueue];

Step 7: Implement callback URL schemes

Some sharers make a trip to a different app (Facebook, Google+, Dropbox, Evernote, Buffer, Pocket) during share - either for authorisation (Single Sign On) or for presenting share dialogue. Here you configure your app to be able to handle callback. If you do not use any of these sharers, you can omit corresponding lines. In your AppDelegate.m file:

  1. add headers:
#import "SHKDropbox.h"
#import "SHKGooglePlus.h"
#import "SHKFacebook.h"
#import "EvernoteSDK.h"
//#import "SHKBuffer.h"
#import "PocketAPI.h"
  1. add (or change, if already exist) these methods:
- (void)applicationDidBecomeActive:(UIApplication *)application
{
    [SHKFacebook handleDidBecomeActive];
    [[EvernoteSession sharedSession] handleDidBecomeActive];
}

- (void)applicationWillTerminate:(UIApplication *)application 
{
    // Save data if appropriate
    [SHKFacebook handleWillTerminate];
}

- (BOOL)application:(UIApplication *)application 
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation
{
    NSString* scheme = [url scheme];

    NSRange pocketPrefixKeyRange = [(NSString *)SHKCONFIG(pocketConsumerKey) rangeOfString:@"-"];
    NSRange range = {0, pocketPrefixKeyRange.location - 1};
    NSString *pocketPrefixKeyPart = [(NSString *)SHKCONFIG(pocketConsumerKey) substringWithRange:range];
    NSString *bundleID = [[NSBundle mainBundle] bundleIdentifier];

    if ([scheme hasPrefix:[NSString stringWithFormat:@"fb%@", SHKCONFIG(facebookAppId)]]) {
        return [SHKFacebook handleOpenURL:url];
    } else if ([[scheme lowercaseString] isEqualToString:[bundleID lowercaseString]]) {
        return [SHKGooglePlus handleURL:url sourceApplication:sourceApplication annotation:annotation];
    } else if ([scheme hasPrefix:[NSString stringWithFormat:@"db-%@", SHKCONFIG(dropboxAppKey)]]) {
        return [SHKDropbox handleOpenURL:url];
    } else if ([[NSString stringWithFormat:@"en-%@", [[EvernoteSession sharedSession] consumerKey]] isEqualToString:[url scheme]]) {
        return [[EvernoteSession sharedSession] canHandleOpenURL:url];
    } else if ([scheme hasPrefix:[NSString stringWithFormat:@"buffer%@", SHKCONFIG(bufferClientID)]]) {
        //return [SHKBuffer handleOpenURL:url];
    }else if ([scheme hasPrefix:[NSString stringWithFormat:@"pocketapp%@", pocketPrefixKeyPart]]) {
        return [[PocketAPI sharedAPI] handleOpenURL:url];
    }

    return YES;
}
  1. Finally, add the custom URL scheme to the file MyiPhoneApp-Info.plist, for the key "URL types" (don't forget to replace [....] by your actual app id's or settings):
<key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleTypeRole</key>
            <string>Evernote</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>en-[consumer key]</string>
            </array>
        </dict>
        <dict>
            <key>CFBundleTypeRole</key>
            <string>Facebook</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>fb[AppId]</string>
            </array>
        </dict>
        <dict>
            <key>CFBundleTypeRole</key>
            <string>Google Plus</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>[bundleID]</string>
            </array>
        </dict>
        <dict>
            <key>CFBundleTypeRole</key>
            <string>Dropbox</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>db-[dropboxAppKey]</string>
            </array>
        </dict>
        <dict>
            <key>CFBundleTypeRole</key>
            <string>Buffer</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>buffer[bufferClientID]</string>
            </array>
        </dict>
    </array>

some more info:

Something went wrong with that request. Please try again.