Cidaas-Facebook 17.8.3

Cidaas-Facebook 17.8.3

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最后发布2017 年 8 月
SwiftSwift 版本3.0
SPM支持 SPM

[Cidaas] 维护。



 
依赖于
FacebookCore>= 0
FacebookLogin>= 0
Cidaas-SDK>= 0
 

  • Cidaas

关于 Cidaas 的更多信息

想了解更多关于 Cidaas 的信息,请访问 CIDaaS

Cidaas 文档

https://docs.cidaas.de/

要求

Operating System    :   iOS 10.0 or above
Xcode               :   9
Swift               :   4.0

安装

Cidaas-Facebook 通过 CocoaPods 提供。要安装,只需将以下行添加到您的 Podfile 中:

pod 'Cidaas-Facebook', '~> 9.4'

创建Facebook应用

以下是创建 Facebook应用 的步骤

  1. 前往 Facebook开发者控制台,添加一个新应用,然后给它一个有效的名称,然后点击 创建应用Id

  2. 注意应用ID

  3. 在左侧,您有导航抽屉。点击 设置 然后 基本

  4. 点击 添加平台 并选择 iOS

  5. 输入您项目的包标识符

  6. 启用 单点登录 并点击 保存更改

入门指南

以下步骤是使用此 Cidaas-Facebook 需要遵循的

  1. 将以下代码复制并粘贴到您的 Info.plist 文件中
<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>fbyour_app_id</string>
        </array>
    </dict>
</array>

<key>FacebookAppID</key>
<string>your fb app id</string>

<key>FacebookDisplayName</key>
<string>your fb app name</string>

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>fbapi</string>
    <string>fb-messenger-api</string>
    <string>fbauth2</string>
    <string>fbshareextension</string>
</array>
  1. 在您的项目的 AppDelegate.swift 文件中,导入 Cidaas_Facebook 模块
import Cidaas_Facebook
  1. 在 AppDelegate 的 application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) 方法内部,将参数重定向到 CidaasFacebook 类方法的 didFinishLaunchingOptions()
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    CidaasFacebook.didFinishLaunchingOptions(application, didFinishLaunchingWithOptions: launchOptions)
    return true
}
  1. 在 AppDelegate 的 application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) 方法内部,将参数重定向到 CidaasFacebook 类方法的 openUrlConfig() 并将其返回
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
    return CidaasFacebook.openUrlConfig(app, open: url, options: options)
}
  1. 在 AppDelegate 的 applicationDidBecomeActive(_ application: UIApplication) 方法内部,将参数重定向到 CidaasFacebook 类方法的 cidaasBecomeActive()
func applicationDidBecomeActive(_ application: UIApplication) {       
    CidaasFacebook.cidaasBecomeActive(application)
}
  1. 创建一个 plist 文件并填写所有键值对输入。以下是所需输入。

plist 文件应如下所示

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

<plist version="1.0">
    <dict>
        <key>  AuthorizationURL  </key>
        <string>  Your authorization url  </string>
            
        <key>  TokenURL  </key>
        <string>  Your token url  </string>
        
        <key>  UserInfoURL  </key>
        <string>  Your user info url  </string>

        <key>SocialUrl</key>
        <string>your social url</string>

        <key>  RedirectURI  </key>
        <string>  Your redirect uri  </string>
    
        <key>  LogoutURL  </key>
        <string>  Your logout url  </string>

        <key>  ClientID  </key>
        <string>  Your client id  </string>

        <key>  ViewType  </key>
        <string>  Your view type  </string>
            
    </dict>
</plist>

有关查找应用ID和URL的详细信息,请参阅 查找AppID和AppURLs

  1. AppDelegate.swift 中说明文件名
CidaasSDK.plistFilename = "Your file name"
  1. 在您的项目 ViewController.swift 文件中,导入 Cidaas_Facebook 模块
import Cidaas_Facebook
  1. 通过设置当前 ViewController 分配 CidaasFacebook 的代理
let cidaas = CidaasFacebook()
cidaas.delegate = self
  1. 调用 cidaasFacebookLogin() 方法并接收 cidaas 访问令牌信息和用户信息作为回调
cidaas.cidaasFacebookLogin { loginResponse in
    // your code here
}

如果您在您的应用中除了 Cidaas-SDK之外还使用 Web 登录,则无需手动调用 cidaasFacebookLogin() 函数,只需简单地初始化 CidaasFacebook 类并将其分配为代理,并启用 facebookSDKEnabled 选项

var cidaas = CidaasFacebook()
cidaas.delegate = self
CidaasSDK.enableNativeFacebook = true

示例代码

AppDelegate.swift

import UIKit
import Cidaas_Facebook
import Cidaas_SDK

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        CidaasSDK.plistFilename = "Cidaas"
        CidaasFacebook.didFinishLaunchingOptions(application, didFinishLaunchingWithOptions: launchOptions)
        return true
    }

    func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
        return CidaasFacebook.openUrlConfig(app, open: url, options: options)
    }
    
    func applicationWillResignActive(_ application: UIApplication) {
    }

    func applicationDidEnterBackground(_ application: UIApplication) {
    }

    func applicationWillEnterForeground(_ application: UIApplication) {
    }

    func applicationDidBecomeActive(_ application: UIApplication) {
        CidaasFacebook.cidaasBecomeActive(application)
    }

    func applicationWillTerminate(_ application: UIApplication) {
    }
}

ViewController.swift

//
//  ViewController.swift
//  Cidaas-Facebook
//
//  Created by Cidaas on 06/09/2017.
//  Copyright (c) 2017 Cidaas. All rights reserved.
//

import UIKit
import Cidaas_Facebook
import Cidaas_SDK

class ViewController: UIViewController, LoaderDelegate {

    @IBOutlet var btn_facebook: UIButton!
    override func viewDidLoad() {
        super.viewDidLoad()
        CidaasSDK.loaderDelegate = self
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
    
    override func viewDidAppear(_ animated: Bool) {
        CidaasSDK.loaderDelegate = self
    }

    @IBAction func btnAction(_ sender: Any) {
        let cidaas = CidaasFacebook()
        cidaas.delegate = self
        cidaas.cidaasFacebookLogin { loginResponse in
            if loginResponse.issuccess == true {
                
                CidaasSDK.getUserInfo(accessToken: (loginResponse.accessTokenEntity?.accessToken)!) { token_response in
                    let alert = UIAlertController(title: "Display Name", message: token_response.displayName, preferredStyle: UIAlertControllerStyle.alert)
                    alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.default))
                    self.present(alert, animated: true, completion: nil)
                }
                
            }
            else {
                let alert = UIAlertController(title: "Error", message: loginResponse.errorMessage, preferredStyle: UIAlertControllerStyle.alert)
                alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.default))
                self.present(alert, animated: true, completion: nil)
            }
        }
    }
    
    func showLoader() {
        CustomLoader.sharedCustomLoaderInstance.showLoader(self.view, using: nil) { (hud) in
            
        }
    }
    
    func hideLoader() {
        CustomLoader.sharedCustomLoaderInstance.hideLoader(self.view)
    }
}

屏幕截图

Screen 1 Screen 2

帮助和支持

更多信息请访问 CIDaaS 支持页面