MobileBankId 0.1.0

MobileBankId 0.1.0

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布上次发布2016年4月
SPM支持 SPM

Lachezar Yankov 维护。



 
依赖项
Alamofire~> 3.0
SwiftyJSON~> 2.3.2
 

  • 作者
  • Lachezar Yankov

MobileBankId

示例项目

要运行示例项目,克隆存储库,然后首先从 Example 目录中运行 pod install

要求

此 Pod 依赖于 Alamofire 3 和 SwiftyJSON。您还需要有一个妥善设置的 BankID 应用

安装

MobileBankId 通过 CocoaPods 提供使用。要安装它,只需将以下行添加到您的 Podfile 中

pod "MobileBankId"

用法

MobileBankId 库的典型用法将在 ViewController 内部。

class ViewController: UIViewController {
    // apiKey and serviceKey are provided from e-identitet.se
    var mobileBankIdProvider = MobileBankIdProvider(apiKey: "...", serviceKey: "...", appScheme: "mybankidscheme")

    override func viewDidLoad() {
        super.viewDidLoad()

        let appDelegate: MobileBankIdAppDelegate = UIApplication.sharedApplication().delegate as! MobileBankIdAppDelegate
        appDelegate.currentMobileBankIdProvider = mobileBankIdProvider
    }

    @IBOutlet weak var bankIdDetails: UITextView!

    @IBAction func startMobileBankIdAuthButtonPressed(sender: AnyObject) {
        mobileBankIdProvider.onAuthSucceeded = {
            [weak self] payload in
            self?.bankIdDetails.text = payload.description
        }
        mobileBankIdProvider.onAuthFailed = {
            [weak self] error, payload in
            if let payload = payload {
                if let code = payload["errorObject"]["code"].string {
                    self?.bankIdDetails.text = "Error details -> \(code)"
                } else {
                    self?.bankIdDetails.text = payload.description
                }
            } else {
                self?.bankIdDetails.text = error.description
            }
        }
        mobileBankIdProvider.authenticate()
    }

    ...

authenticate() 方法将启动 Mobile BankID 应用,一旦身份验证过程完成,BankID 应用将控制权交回您的应用,并调用 application:app:openUrl:options。您需要让您的 AppDelegate 遵从 MobileBankIdAppDelegate 并添加以下代码,以完成身份验证过程并获取用户数据。

class AppDelegate: UIResponder, UIApplicationDelegate, MobileBankIdAppDelegate {
    // currentMobileBankIdProvider must be weak reference, so that it wont let the ViewController leak
    weak var currentMobileBankIdProvider: MobileBankIdProvider?
    ...
    func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
        return currentMobileBankIdProvider?.handleLaunchFromMobileBankIdApp(url: url, options: options) ?? false
    }
}

最后一步是在 info.plist 中注册一个方案,这是您的应用在从 Mobile BankID 应用回调时预期使用的。

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLName</key>
        <string>com.example.mybankidscheme</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>mybankidscheme</string>
        </array>
    </dict>
</array>

作者

Lachezar Yankov,[email protected]

许可证

MobileBankId 基于 MIT 许可证提供。有关更多信息,请参阅 LICENSE 文件。