文丨lyh165
發(fā)布時(shí)間:2018-09-26 (周三 廣州/晴)
最后更新時(shí)間:2018-09-26 (周三 廣州/晴)
小貼士:記住要科學(xué)上網(wǎng)才能訪問(wèn)他們的官網(wǎng).
推薦科學(xué)上網(wǎng)<shadowrocks>
https://e.2333.tn/
官方文檔 https://developers.line.me/en/
集成文檔 https://developers.line.me/en/docs/ios-sdk/integrate-line-login/
溫馨提示:在官方先要?jiǎng)?chuàng)建app應(yīng)用, 1.獲取Channel ID, 2.綁定iOS bundle ID
一、UI

image.png
二、項(xiàng)目-系統(tǒng)依賴庫(kù)

系統(tǒng)依賴庫(kù)
三、info.plist

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;
}
// 本應(yīng)用打開(kāi)第三方應(yīng)用
- (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; // 設(shè)置代理
}
- (IBAction)LineLogin:(UIButton *)sender {
[[LineSDKLogin sharedInstance] startLogin]; // 使用line登錄
}
// line登錄返回的授權(quán)信息
- (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); // 訪問(wèn)令牌
NSLog(@"userID: %@", userID); // 用戶id
NSLog(@"displayName: %@", displayName); // 用戶昵稱
NSLog(@"statusMessage: %@", statusMessage);
NSLog(@"pictureURL: %@", pictureURL); // 頭像
NSString *authMsg = [NSString stringWithFormat:@"授權(quán)返回的信息: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;
}
}
}
集成步驟說(shuō)明
核心代碼每個(gè)步驟在下面了
參考
https://developers.line.me/en/docs/ios-sdk/integrate-line-login/
記得是line login應(yīng)用
1.配置info.plist
ChannelID
LSApplicationQueriesSchemes(白名單)
2.添加系統(tǒng)需要依賴的庫(kù)
3.處理調(diào)用第三方應(yīng)用
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options
{
return [[LineSDKLogin sharedInstance] handleOpenURL:url];
}
4.在登錄界面處理
3.1 設(shè)置代理 [LineSDKLogin sharedInstance].delegate = self;
3.3 按鈕點(diǎn)擊 觸發(fā)line的登錄 [[LineSDKLogin sharedInstance] startLogin];
3.2 監(jiān)聽(tīng)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); // 訪問(wèn)令牌
NSLog(@"userID: %@", userID); // 用戶id
NSLog(@"displayName: %@", displayName); // 用戶昵稱
NSLog(@"statusMessage: %@", statusMessage);
NSLog(@"pictureURL: %@", pictureURL); // 頭像
NSString *authMsg = [NSString stringWithFormat:@"授權(quán)返回的信息: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;
}
}
}