使用手動拖入Facebook 登錄SDK 方式接入
1. 開發(fā)者平臺 - 登錄/注冊賬號 - 創(chuàng)建應(yīng)用 - 選擇應(yīng)用的用途(第三方游戲應(yīng)用) - 輸入應(yīng)用顯示名稱碟渺、應(yīng)用聯(lián)系郵箱 - 點擊創(chuàng)建應(yīng)用編號…
2. 為應(yīng)用添加產(chǎn)品 - Facebook登錄 - 點擊iOS
3. 選擇接入方式 - SDK:FB SDK
4. 點擊下載iOS版SDK
5. 添加項目Bundle ID
6. 啟用單點登錄
7. 配置info.plist
注:頁面左上角
<key>FacebookAppID</key>
<string>應(yīng)用編號</string>
<key>FacebookDisplayName</key>
<string>Facebook顯示名稱</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fbapi20130214</string>
<string>fbapi20130410</string>
<string>fbapi20130702</string>
<string>fbapi20131010</string>
<string>fbapi20131219</string>
<string>fbapi20140410</string>
<string>fbapi20140116</string>
<string>fbapi20150313</string>
<string>fbapi20150629</string>
<string>fbapi20160328</string>
<string>fbauth</string>
<string>fb-messenger-share-api</string>
<string>fbauth2</string>
<string>fbshareextension</string>
</array>
8. 添加依賴庫
注:部分依賴庫是Google登錄中使用
9. 配置URL Types
1)組成URL Types:fb + 應(yīng)用編號
2)配置URL Types
相關(guān)代碼
10. AppDelegate.swift
import FBSDKCoreKit
func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool {
ApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions)
return true
}
func application( _ app:UIApplication, open url:URL, options: [UIApplication.OpenURLOptionsKey :Any] = [:] ) -> Bool {
return ApplicationDelegate.shared.application( app, open: url, sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String, annotation: options[UIApplication.OpenURLOptionsKey.annotation])
}
11. iOS13.0配置 SceneDelegate.swift
func scene(_ scene:UIScene, openURLContexts URLContexts:Set<UIOpenURLContext>) {
guard let url = URLContexts.first?.url else { return }
ApplicationDelegate.shared.application( UIApplication.shared, open: url, sourceApplication: nil, annotation: [UIApplication.OpenURLOptionsKey.annotation] )
}
12.1 發(fā)起登錄 - Facebook 原生按鈕
- 創(chuàng)建FBLoginButton 對象煞聪,添加到view中
let loginButton = FBLoginButton()
loginButton.center = view.center view.addSubview(loginButton)
loginButton.delegate = self
view.addSubview(loginButton)
- 遵循LoginButtonDelegate 并實現(xiàn)代理方法
func loginButton(_ loginButton: FBLoginButton, didCompleteWith result: LoginManagerLoginResult?, error: Error?) {
if result!.isCancelled {
print("取消登錄")
} else {
print("loginButton")
}
}
func loginButtonDidLogOut(_ loginButton: FBLoginButton) {
print("loginButtonDidLogOut")
}
12.2 發(fā)起登錄 - 自定義按鈕
let login = LoginManager.init()
login.logIn(permissions: ["public_profile", "email"], from: self) { (result, error) in
}
13 進入調(diào)試
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者