使用非常简单,只需将 "LinkedInHelper.h" 导入到您想要使用此库的控制器中
如果您想使用 LinkedIn Api 登录用户,可以轻松地获取如下信息
#import "LinkedInHelper.h"
@implementation ViewController
- (void)fetchUserInformations {
LinkedInHelper *linkedIn = [LinkedInHelper sharedInstance];
linkedIn.cancelButtonText = @"Close"; // Or any other language But Default is Close
NSArray *permissions = @[@(BasicProfile),
@(EmailAddress),
@(Share),
@(CompanyAdmin)];
linkedIn.showActivityIndicator = YES;
#warning - Your LinkedIn App ClientId - ClientSecret - RedirectUrl
[linkedIn requestMeWithSenderViewController:self
clientId:@"" // Your App Client Id
clientSecret:@"" // Your App Client Secret
redirectUrl:@"" // Your App Redirect Url
permissions:permissions
state:@"" // Your client state
successUserInfo:^(NSDictionary *userInfo) {
// Whole User Info
NSLog(@"user Info : %@", userInfo);
}
failUserInfoBlock:^(NSError *error) {
NSLog(@"error : %@", error.userInfo.description);
}
];
}
@end
您可以根据以下方式检查 LinkedIn 访问令牌是否仍然有效
- (BOOL)isLinkedInAccessTokenValid {
return [LinkedInHelper sharedInstance].isValidToken;
}
您可以通过 web view 自动获取用户信息,无需再次获取授权代码。
这将自动获取用户信息,多亏了有效的访问令牌
- (void)getUserInfo {
LinkedInHelper *linkedIn = [LinkedInHelper sharedInstance];
// If user has already connected via linkedin in and access token is still valid then
// No need to fetch authorizationCode and then accessToken again!
#warning - To fetch user info automatically without getting authorization code, accessToken must be still valid
if (linkedIn.isValidToken) {
// So Fetch member info by elderyly access token
[linkedIn autoFetchUserInfoWithSuccess:^(NSDictionary *userInfo) {
// Whole User Info
NSLog(@"user Info : %@", userInfo);
} failUserInfo:^(NSError *error) {
NSLog(@"error : %@", error.userInfo.description);
}];
}
}
有关更多信息,请查看演示应用。
我在代码中尽力而为,通过编写优秀的文档。
此库需要 iOS 6.0 或更高版本的部署目标。
LinkedinIOSHelper 通过 CocoaPods 提供。要安装
它,只需将以下行添加到 Podfile
pod 'LinkedinIOSHelper', '~> 1.0.7'
Ahmet Kazım Günay, [email protected]
LinkedinIOSHelper 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。