ForgeRock SDKs

Prerequisites for authentication

To start this example, your ViewController.swift file should resemble the following:

    //
    //  ViewController.swift
    //  DemoApp
    //

    import UIKit
    import FRAuth

    class ViewController: UIViewController {

        @IBOutlet weak var statusLabel: UILabel?
        @IBOutlet weak var loginButton: UIButton?

        override func viewDidLoad() {
            super.viewDidLoad()
            // Do any additional setup after loading the view.

            FRLog.setLogLevel([.error, .network])

            do {
                try FRAuth.start()
                print("SDK initialized successfully")
            }

            catch {
                  print(error)
            }

            updateStatus()

        }

        func updateStatus() {
            if let _ = FRUser.currentUser {
                statusLabel?.text = "User is authenticated"
            }
            else {
                statusLabel?.text = "User is not authenticated"
            }
        }

        @IBAction func loginButtonPressed(sender: UIButton) {
            print("Login button is pressed")

        }
    }
  1. Make sure to save your changes to the file.

  2. In the Main storyboard, add a UILabel and a UIButton.

  3. Link these items to the IBOutlets and IBActions in the ViewController class.

Copyright © 2010-2022 ForgeRock, all rights reserved.