Updated 14 December 2016
Sometimes we require to Integrate Application with LinkedIn Account so that user can easily login into the application . for doing that we require linkedIn application installed into your iPhone.
Here some following steps to follow.
1: Download LinkedIn SDK .
https://developer.linkedin.com/downloads#iossdk
2: Register your account in LinkedIn developer site and fill in mobile part.
a: fill your application bundle id and click on add after that update.
you can also follow that steps: (go to the middle of that page.) https://developer.linkedin.com/docs/ios-sdk
3: Configure your application’s info.plist
1 2 3 4 5 6 7 8 9 10 11 12 |
<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> |
4: for iOS 9 Compatibility
Add the following configuration to your application’s Info.plist file:
1 2 3 4 5 6 |
<key>LSApplicationQueriesSchemes</key> <array> <string>linkedin</string> <string>linkedin-sdk2</string> <string>linkedin-sdk</string> </array> |
5: App Transport Security (Update ininfo.plist)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<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> |
6: Import the SDK
Open the Mobile SDK for iOS archive and drag LinkedIn-SDK.framework into the Xcode Project Navigator pane of your project.
7: 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. deep linking)
1 2 3 4 5 6 |
- (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; } |
8: Now here is sample of code for creating uibotton and their events
1 2 3 4 5 |
UIButton *linkDinSignIn = [UIButton buttonWithType:UIButtonTypeCustom]; [linkDinSignIn addTarget:self action:@selector(callingLinkdinSigninButton:) forControlEvents:UIControlEventTouchUpInside]; [linkDinSignIn setImage:[UIImage imageNamed:@"linkDinSignIn"] forState:UIControlStateNormal]; linkDinSignIn.frame = CGRectMake(SCREEN_WIDTH/2-80, 395, 160, 35); [self.view addSubview:linkDinSignIn]; |
there click events :
it will launch the linkedIn application in your phone and take some data;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
-(void)callingLinkdinSigninButton :(UIButton*)button{ [LISDKSessionManager createSessionWithAuth:[NSArray arrayWithObjects:LISDK_BASIC_PROFILE_PERMISSION, LISDK_EMAILADDRESS_PERMISSION, nil] state:@"some state" showGoToAppStoreDialog:YES successBlock:^(NSString *returnState) { // NSLog(@"%s","success called!"); LISDKSession *session = [[LISDKSessionManager sharedInstance] session]; // NSLog(@"value=%@ isvalid=%@",[session value],[session isValid] ? @"YES" : @"NO"); NSMutableString *text = [[NSMutableString alloc] initWithString:[session.accessToken description]]; [text appendString:[NSString stringWithFormat:@",state=\"%@\"",returnState]]; // NSLog(@"Response label text %@",text); [self fetchLinkdinData]; [GlobalData alertController:currentWindow msg:[globalObjectCustomerLogin.languageBundle localizedStringForKey:@"pleaseWait" value:@"" table:nil]]; } errorBlock:^(NSError *error) { NSLog(@"%s %@","error called! ", [error description]); } ]; } |
There is one function ([self fetchLinkdinData];) that will fetch data from application.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
-(void) fetchLinkdinData{ [[LISDKAPIHelper sharedInstance] getRequest:@"https://api.linkedin.com/v1/people/~:(email-address,formatted-name,phone-numbers,public-profile-url,picture-url,picture-urls::(original))" success:^(LISDKAPIResponse *response){ NSData* data = [response.data dataUsingEncoding:NSUTF8StringEncoding]; NSDictionary *dictResponse = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; NSArray *arr = [dictResponse[@"formattedName"] componentsSeparatedByString:@" "]; long count = [arr count]; if(count == 2){ firstNameVal = arr[0]; lastNameVal = arr[1]; } else if(count >2){ firstNameVal = arr[0]; lastNameVal = arr[count-1]; } else{ firstNameVal = arr[0]; lastNameVal = @""; } pictureURL = dictResponse[@"pictureUrl"]; emailAddressVal = dictResponse[@"emailAddress"]; isSocial = @"true"; // NSLog(@"Authenticated user name : %@ %@ %@ %@", firstNameVal,lastNameVal,pictureURL,emailAddressVal); // for logout from linkdin application [LISDKSessionManager clearSession]; } error:^(LISDKAPIError *apiError){ NSLog(@"Error : %@", apiError); }]; } |
9: Now you can Do anything from that data.
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
This line gives me session is invalid. Any idea what I am doing wrong?