CocosCreator 2.4.5 整合Line登入(IOS App)
- 承鑫 郭
- 2021年7月22日
- 讀畢需時 1 分鐘

建立Line Provider以及Line Login Channel

CocosCreator建立Login按鈕以及綁定事件
//Line登入
lineLogin: function () {
console.log("Line login");
if (cc.sys.isNative) { .
if (cc.sys.os == cc.sys.OS_ANDROID) {
} else if (cc.sys.os == cc.sys.OS_IOS) {
let className = "AppController";
let methodName = "lineLogin";
jsb.reflection.callStaticMethod(className, methodName);
}
}
Xcode專案設定(CocosCreator導出的專案為ObjectiveC)
下載IOS Line SDK並導入到Xcode專案
Build Phases => Link Binary With Libraries 加入以下framework
LineSDK.framework
CoreTelephony.framework
Security.framework
Build Phases => Copy Bundle Resources 加入以下bundle
LineSDKResource.bundle
使用 Open As => Source Code 編輯 Info.plist
LineSDKConfig</key>
<dict>
<key>ChannelID</key>
<string>123456789</string>
</dict>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>line3rdp.$(PRODUCT_BUNDLE_IDENTIFIER)</string>
</array>
</dict>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>lineauth2</string>
<string>line3rdp.$(PRODUCT_BUNDLE_IDENTIFIER)</string>
</array>
AppController.mm 加入以下程式碼
1.設置line代理
// Set the LINE Login Delegate
[LineSDKLogin sharedInstance].delegate = self;
2.設定開啟第三方line App
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options
{
return [[LineSDKLogin sharedInstance] handleOpenURL:url];
}
3.Login成功Callback設定
#pragma mark LineSDKLoginDelegate
- (void)didLogin:(LineSDKLogin *)login
credential:(LineSDKCredential *)credential
profile:(LineSDKProfile *)profile
error:(NSError *)error
{
if (error) {
NSLog(@"LINE Login Failed with Error: %@", error.description);
return;
}
NSLog(@"LINE Login Succeeded");
//做Login成功要做的事
}
連結你的Line Channel和App

Demo

疑難排解
Assigning to 'id<LineSDKLoginDelegate> _Nullable' from incompatible type 'AppController *'
Sol:@interface AppController () 後面加 <LineSDKLoginDelegate>
Comments