Installation

1. Add FlockSdk to Your Project

Using Swift Package Manager (SPM):

  1. Open your Xcode project.
  2. Go to File > Add Packages.
  3. Enter the repository URL for FlockSdk: https://github.com/flock-solutions/ios-sdk.
  4. Select a version and add the package to your project.

Usage

1. Initialize the SDK

In your AppDelegate or SceneDelegate, configure the SDK with your publicAccessKey:

import FlockSdk

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(_ application: UIApplication,
                     didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        FlockSdk.initialize(publicAccessKey: "your-public-access-key")
        return true
    }
}

2. Identify Customers

The identify method should be called after a user successfully logs in or creates an account. This links the user’s details to their Flock account.

Example:

import FlockSdk

func handleLoginSuccess(user: User) {
    FlockSdk.identify(externalUserId: user.id,
                      email: user.email,
                      name: user.name) { result in
        switch result {
        case .success(let response):
            print("Identify Response: \(response)")
        case .failure(let error):
            print("Identify Error: \(error)")
        }
    }
}

3. Open Referrals WebView

To show the referral page for an referrer, use the openPage method with the referrer page type. You can handle events like the closed action.

Example:

import FlockSdk
import UIKit

func showReferralsWebView(from viewController: UIViewController) {
    FlockSdk.openPage(type: 'referrer', from: viewController) { event in
        if event == .closed {
            print("WebView closed")
        }
    }
}

4. Open Invitee WebView

For an invitee, use the openPage method with the invitee page type. This method supports onSuccess, onInvalid, and closed callbacks.

Example:

import FlockSdk
import UIKit

func showInviteeWebView(from viewController: UIViewController) {
    FlockSdk.openPage(type: 'invitee', from: viewController) { event in
        switch event {
        case .success:
            print("Invitee successfully onboarded")
        case .invalid:
            print("Invalid invitation link")
        case .closed:
            print("WebView closed")
        }
    }
}

5. Post-Success Flow for Invitees (Optional)

After a successful onboarding of an invitee, you can choose to either navigate the user to your custom success page or open a Flock-hosted success page. Use the openHostedSuccessPage method for the latter option.

Example:

func handleInviteeSuccess(from viewController: UIViewController) {
    FlockSdk.openPage(type: 'invitee?state=success', from: viewController) { event in
        if event == .closed {
            print("Hosted success page closed")
        }
    }
}


Notes

Error Handling

  • Ensure network errors are handled when calling identify.
  • Provide fallback UI if the WebView fails to load.

Testing

  • Use mock APIs during development to avoid triggering actual requests to Flock’s backend.

FAQ

Q: What iOS versions are supported?

A: FlockSdk supports iOS 11.0 and above.

Q: Can I customize WebView actions?

A: Yes, you can use the event handlers provided for WebView methods to customize the behavior.


Support

For questions or issues, contact the Flock support team at support@withflock.com.


Thank you for using FlockSdk!