无法在ios中为LinkedIn创建登录会话

时间:2016-04-15 09:48:03

标签: ios objective-c linkedin

能够启动应用程序以创建会话但在登录到应用程序后,LISDKSessionManager succuess块不会被调用

[LISDKSessionManager createSessionWithAuth:[NSArray arrayWithObjects:LISDK_FULL_PROFILE_PERMISSION, nil]
                                         state:nil
                        showGoToAppStoreDialog:YES
                                  successBlock:^(NSString *returnState) {
                                      if(returnState){
                                       NSLog(@"%s","success called!");

                                      }
                                      if (returnState) {
                                          [self updateControlsWithResponseLabel:YES];
                                      }
                                      // 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);
                                      _responseLabel.text = text;
                                      self.lastError = nil;
                                      // retain cycle here?
                                      [self updateControlsWithResponseLabel:NO];

                                  }
                                    errorBlock:^(NSError *error) {
                                        NSLog(@"%s %@","error called! ", [error description]);
                                        self.lastError = error;
                                        //  _responseLabel.text = [error description];
                                        [self updateControlsWithResponseLabel:YES];
                                    }
     ];

2 个答案:

答案 0 :(得分:1)

最后请注意,linkedIn SDK登录仅适用于iPhone而不适用于iPad

答案 1 :(得分:0)

在AppDelegate中:

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

并在你的按钮操作方法中调用:

    NSArray *permissions = [NSArray arrayWithObjects:LISDK_BASIC_PROFILE_PERMISSION, nil];
   [LISDKSessionManager createSessionWithAuth:permissions state:nil showGoToAppStoreDialog:YES successBlock:^(NSString *returnState)
    {
      NSLog(@"%s","success called!");
      LISDKSession *session = [[LISDKSessionManager sharedInstance] session];
      NSLog(@"Session : %@", session.description);
   } errorBlock:^(NSError *error)
   { 
     NSLog(@"%s","error called!");
  }];

  // call this to fetch basic information of user logged in .   
   -(void) getRequest:(NSString*)token
   { 

    [[LISDKAPIHelper sharedInstance] getRequest:@"https://api.linkedin.com/v1/people/~"
                                    success:^(LISDKAPIResponse *response)
      {
        NSData* data = [response.data dataUsingEncoding:NSUTF8StringEncoding];
        NSDictionary *dictResponse = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"Authenticated user name : %@ %@", [dictResponse valueForKey: @"firstName"], [dictResponse valueForKey: @"lastName"]);
       } 
    error:^(LISDKAPIError *apiError)
    {
      NSLog(@"Error : %@", apiError);
   }];
  }