文丨lyh165
发布时间:2018-09-26 (周三 广州/晴)
最后更新时间:2018-09-26 (周三 广州/晴)
小贴士:记住要科学上网才能访问他们的官网.
推荐科学上网<shadowrocks>
https://e.2333.tn/
官方文档 https://developers.line.me/en/
集成文档 https://developers.line.me/en/docs/ios-sdk/integrate-line-login/
温馨提示:在官方先要创建app应用, 1.获取Channel ID, 2.绑定iOS bundle ID
一、UI
二、项目-系统依赖库
三、info.plist
四、code
AppDelegate.m
#import "AppDelegate.h"
#import <LineSDK/LineSDK.h>
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
return YES;
}
// 本应用打开第三方应用
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options
{
return [[LineSDKLogin sharedInstance] handleOpenURL:url];
}
ViewController.m
#import "ViewController.h"
#import <LineSDK/LineSDK.h>
@interface ViewController ()<LineSDKLoginDelegate>
@property (weak, nonatomic) IBOutlet UITextView *tv_content;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[LineSDKLogin sharedInstance].delegate = self; // 设置代理
}
- (IBAction)LineLogin:(UIButton *)sender {
[[LineSDKLogin sharedInstance] startLogin]; // 使用line登录
}
// line登录返回的授权信息
- (void)didLogin:(LineSDKLogin *)login
credential:(LineSDKCredential *)credential
profile:(LineSDKProfile *)profile
error:(NSError *)error
{
if (error) {
// Login failed with an error. Use the error parameter to identify the problem.
NSLog(@"Error: %@", error.localizedDescription);
}
else {
// Login success. Extracts the access token, user profile ID, display name, status message, and profile picture.
NSString * accessToken = credential.accessToken.accessToken;
NSString * userID = profile.userID;
NSString * displayName = profile.displayName;
NSString * statusMessage = profile.statusMessage;
NSURL * pictureURL = profile.pictureURL;
NSLog(@"accessToken: %@", accessToken); // 访问令牌
NSLog(@"userID: %@", userID); // 用户id
NSLog(@"displayName: %@", displayName); // 用户昵称
NSLog(@"statusMessage: %@", statusMessage);
NSLog(@"pictureURL: %@", pictureURL); // 头像
NSString *authMsg = [NSString stringWithFormat:@"授权返回的信息:accessToken: %@,userID: %@,displayName: %@,statusMessage: %@,pictureURL: %@",accessToken,userID,displayName,statusMessage,pictureURL];
self.tv_content.text = authMsg;
NSString * pictureUrlString;
// If the user does not have a profile picture set, pictureURL will be nil
if (pictureURL) {
pictureUrlString = profile.pictureURL.absoluteString;
}
}
}
集成步骤说明
核心代码每个步骤在下面了
参考
https://developers.line.me/en/docs/ios-sdk/integrate-line-login/
记得是line login应用
1.配置info.plist
ChannelID
LSApplicationQueriesSchemes(白名单)
2.添加系统需要依赖的库
3.处理调用第三方应用
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options
{
return [[LineSDKLogin sharedInstance] handleOpenURL:url];
}
4.在登录界面处理
3.1 设置代理 [LineSDKLogin sharedInstance].delegate = self;
3.3 按钮点击 触发line的登录 [[LineSDKLogin sharedInstance] startLogin];
3.2 监听login代理
code
- (void)didLogin:(LineSDKLogin *)login
credential:(LineSDKCredential *)credential
profile:(LineSDKProfile *)profile
error:(NSError *)error
{
if (error) {
// Login failed with an error. Use the error parameter to identify the problem.
NSLog(@"Error: %@", error.localizedDescription);
}
else {
// Login success. Extracts the access token, user profile ID, display name, status message, and profile picture.
NSString * accessToken = credential.accessToken.accessToken;
NSString * userID = profile.userID;
NSString * displayName = profile.displayName;
NSString * statusMessage = profile.statusMessage;
NSURL * pictureURL = profile.pictureURL;
NSLog(@"accessToken: %@", accessToken); // 访问令牌
NSLog(@"userID: %@", userID); // 用户id
NSLog(@"displayName: %@", displayName); // 用户昵称
NSLog(@"statusMessage: %@", statusMessage);
NSLog(@"pictureURL: %@", pictureURL); // 头像
NSString *authMsg = [NSString stringWithFormat:@"授权返回的信息:accessToken: %@,userID: %@,displayName: %@,statusMessage: %@,pictureURL: %@",accessToken,userID,displayName,statusMessage,pictureURL];
self.tv_content.text = authMsg;
NSString * pictureUrlString;
// If the user does not have a profile picture set, pictureURL will be nil
if (pictureURL) {
pictureUrlString = profile.pictureURL.absoluteString;
}
}
}