Getting Started with the Mobile SDK for iOS

Easily integrate LinkedIn into your iOS applications

Overview

The Mobile SDK for iOS decreases your app's time to market by providing out-of-box support for LinkedIn natively inside your iOS applications, saving you time to work on the unique parts of your application that matter the most.

The SDK provides:

  • Single sign-on (SSO) authentication, in conjunction with the official LinkedIn mobile application.
  • A convenient wrapper for making authenticated calls to LinkedIn's REST APIs.
  • Deeplinking to additional member content in the official LinkedIn iOS app.
  • A sample application that demonstrates all of the SDK's features.

This guide will introduce key SDK concepts and will walk you through getting the bundled sample application up and running.

Setting up your development environment

Get the latest Xcode

Ensure that you are running Xcode version 6.1.1 or greater in your development environment.

Download the SDK

Download the latest version of the LinkedIn Mobile SDK for iOS.

Building the Sample Applications

The following instructions detail how to build the LinkedIn Mobile SDK and associated sample projects within the Xcode environment:

  1. Download and open the latest version of the LinkedIn Mobile SDK for iOS.
  2. Open either the eventsApp or SampleApp folder.
  3. Double-click on either the eventsapp.xcodeproj or SampleApp.xcodeproj file.
  4. Select Product -> Run from the top navigation.
iOS Sample app

You should now be able to run the Sample App and Events App projects.  Remember that the Mobile SDK-enabled applications require the official LinkedIn iOS app to be installed on the device to function properly.

Finally, while the Sample App will run fine natively, if you want to run the Events App or any of your own projects, you must configure their package names and key hashes within your LinkedIn Application's configuration, as described below.

Associate your iOS app with your LinkedIn app

If you have not already done so, create an application. If you have an existing LinkedIn application, configure it on the Developer website.  

Go to the the “Mobile” setting page, and configure your application’s Bundle ID value in your LinkedIn application settings.

You can find your Bundle ID value in the “General” properties of your Xcode project:

  • Xcode Bundle ID

Configure your Bundle ID

Associate your iOS application with your LinkedIn application by configuring your Bundle ID value(s) within your LinkedIn application.  Multiple Bundle ID values allow a collection of applications (e.g. trial vs. free versions, a suite of related apps, etc.) to leverage the same LinkedIn application privileges and access tokens.

  • iOS Bundle Identifier configuration

Determine your LinkedIn App ID value

Before you can make the necessary changes to your Info.plist file, you need to know what your LinkedIn application’s Application ID is.

As seen above, it can be found on the “Mobile” settings page, listed directly underneath the “iOS Settings” header, within the application management tool.

Configure your application's info.plist

Locate the Supporting Files -> Info.plist file in your Xcode project and add the following values.

Note the two locations within the file where you need to substitute your LinkedIn Application ID value:

Info.plist
<key>LIAppId</key>
<string>{Your LinkedIn app ID}</string>

<key>CFBundleURLTypes</key>
<array>
	<dict>
		<key>CFBundleURLSchemes</key>
		<array>
			<string>li{Your LinkedIn app ID}</string>
		</array>
	</dict>
</array>

Once complete, your application properties should look like this:

  • Xcode application properties

iOS 9 Compatibility

If you are targeting iOS 9 support in your application, there are some additional steps required to be able to successfully build and run your app:

Whitelisting LinkedIn Custom Schemes

In iOS 9, you will need to specifically whitelist the schemes exposed by the LinkedIn iOS application.  Add the following configuration to your application's Info.plist file:

Info.plist
<key>LSApplicationQueriesSchemes</key>
<array>
    <string>linkedin</string>
    <string>linkedin-sdk2</string>
    <string>linkedin-sdk</string>
</array>

Bitcode Support

Bitcode compiling for iOS 9 is supported as of version 1.0.7 of the SDK.

App Transport Security

As of iOS 9, Apple is enforcing the use of secure HTTPS connections between an app and server.  If your application is exclusively making calls over HTTPS, you should have no compatibility issues.  However, if your application needs to make requests to insecure HTTP endpoints, you must specify the insecure domain(s) in your app's Info.plist file.  

For example, the following configuration whitelists HTTP calls to *.linkedin.com servers:

Info.plist
<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>linkedin.com</key>
        <dict>
            <key>NSExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <key>NSIncludesSubdomains</key>
            <true/>                
            <key>NSExceptionRequiresForwardSecrecy</key>
            <false/>
        </dict>
    </dict>
</dict>

Using the SDK

The following information will explain how to use the various features that the SDK provides to you, including:

  • Authenticating LinkedIn members
  • Making authenticated API calls
  • Deeplinking to additional member content

Please also consider taking a look at the sample application included with the SDK for complete functional implementation examples of all of the features outlined below.

Import the SDK

Open the Mobile SDK for iOS archive and drag linkedin-sdk.framework into the Xcode Project Navigator pane of your project.

Import SDK header

To enable code completion for a smoother development experience, we recommend you include the following header anywhere in your code where you reference the Mobile SDK for iOS:

Objective-c
#import <linkedin-sdk/LISDK.h>

Handle responses from the LinkedIn mobile app

Add the following method to your AppDelegate.m source code to enable the LinkedIn App to give control back your application in situations in situations where you are brought outside of the context of your application (e.g. deeplinking)

Objective-C
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    if ([LISDKCallbackHandler shouldHandleUrl:url]) {
        return [LISDKCallbackHandler application:application openURL:url sourceApplication:sourceApplication annotation:annotation];
    }
    return YES;
}

Making Authenticated REST API calls

Once your users are authenticated and have authorized your application, you can easily make calls to LinkedIn's REST API on their behalf. The LISDKAPIHelper object provides helper methods for all of the necessary HTTP verbs, and will take care of ensuring the current user’s access token is applied to the request.

To understand all of the possible API calls that can be made using these helper methods, please consult LinkedIn's complete REST API documentation .

getRequest

Make an HTTP GET request to LinkedIn's REST API using the currently authenticated user's credentials. If successful, a LISDKAPIResponse object containing the LinkedIn response will be returned.

Objective-C
[[LISDKAPIHelper sharedInstance] getRequest:(NSString *)url
           success:(void(^)(LISDKAPIResponse *))success
             error:(void(^)(LISDKAPIError *))error]

postRequest

Make an HTTP POST request to LinkedIn's REST API using the currently authenticated user's credentials.  If successful, a LISDKAPIResponse object containing the LinkedIn response will be returned.

Objective-C
[[LISDKAPIHelper sharedInstance] postRequest:(NSString *)url
               body:(NSData *)body
            success:(void(^)(LISDKAPIResponse *))successCompletion
              error:(void(^)(LISDKAPIError *))errorCompletion]
Objective-C
[[LISDKAPIHelper sharedInstance] postRequest:(NSString *)url
         stringBody:(NSString *)stringBody
            success:(void(^)(LISDKAPIResponse *))successCompletion
              error:(void(^)(LISDKAPIError *))errorCompletion]

Cancelling in-progress requests

During your application's workflow, there may be occasions where you will want to cancel any in-progress API requests.  This is made possible by calling the cancelCalls method.

Deeplinking to content inside the LinkedIn mobile application

The mobile SDK provides you the capability to deeplink to a specific member's profile directly within the official LinkedIn mobile application.  This capability is found in the LISDKDeeplinkHelper class.  Use one of the following two methods to trigger the opening of a full LinkedIn profile within the official LinkedIn iOS application:

viewCurrentProfileWithState

This method will open the currently authenticated user's LinkedIn profile.  Users have the right to see more information about themselves than of other members.  Although it will not fail, they may end up seeing less of their own profile information than possible if you send them to the LinkedIn application using viewOtherProfile with their member ID, rather than using this method.

This method takes the following arguments:

  • state - The state to return to your application when a user backs out of the LinkedIn application.
  • showDialog - A boolean to determine whether the user should be presented with a dialog prompting them to go to the App Store if they do not have the LinkedIn iOS app installed.  If false, they will be taken there directly, without prompt, if necessary.
  • success - A handler method that is executed when the deeplink action completes successfully.
  • error - A handler method that is executed if the attempt to deeplink fails.

Sample:

Objective-C
DeeplinkSuccessBlock success = ^(NSString *returnState) {
    NSLog(@"Success with returned state: %@",returnState);
};
DeeplinkErrorBlock error = ^(NSError *error, NSString *returnState) {
    NSLog(@"Error with returned state: %@", returnState);
    NSLog(@"Error %@", error);
};
[[LISDKDeeplinkHelper sharedInstance] viewCurrentProfileWithState:@"viewMyProfileButton" success:success error:error];

viewOtherProfile

This method will open a specific member profile within the official LinkedIn application.  It takes the following arguments:

  • memberId - The ID of the LinkedIn member whose profile you want to send the user to.
  • state - The state to return to your application when a user backs out of the LinkedIn application.
  • showDialog - A boolean to determine whether the user should be presented with a dialog prompting them to go to the App Store if they do not have the LinkedIn iOS app installed. If false, they will be taken there directly, without prompt, if necessary.
  • success - A handler method that is executed when the deeplink action completes successfully.
  • error - A handler method that is executed if the attempt to deeplink fails.

The memberID is a value that is unique to your particular LinkedIn application, representing a specific LinkedIn member. You can retrieve the current user's id by making a REST API call to LinkedIn's Profile API using the SDK's API wrapper method.

Storing member ID values on your own server allows your application to direct users to the official LinkedIn profiles for any other users that have authorized your mobile application.  You will not be able to retrieve valid member ID's for anyone who has not previously authorized your application.

Sample:

Objective-C
DeeplinkSuccessBlock success = ^(NSString *returnState) {
    NSLog(@"Success with returned state: %@",returnState);
};
DeeplinkErrorBlock error = ^(NSError *error, NSString *returnState) {
    NSLog(@"Error with returned state: %@", returnState);
    NSLog(@"Error %@", error);
};
NSString *memberId = self.memberIdText.text;
[[LISDKDeeplinkHelper sharedInstance] viewOtherProfile:memberId withState:@"viewMemberProfileButton" success:success error:error];