Getting Started

ReferralHero iOS Swift SDK

Getting Started

To start using the ReferralHero SDK, you will need to add it to your project as a framework. These can be downloaded from Here: https://github.com/maitre-app/ReferralHero-iOS

You can install the ReferralHero SDK using Swift Package Manager by following these steps:

  1. Open Your Xcode Project

  • Open your .xcodeproj or .xcworkspace in Xcode.

  1. Add Swift Package Dependency

  2. Go to FileAdd Packages…

  3. In the search or URL field, paste:

    https://github.com/maitre-app/ReferralHero-iOS.git
  4. Click Add Package.

  5. Import and Use SDK

🛠 Option 2: Manual Installation

Download the SDK.

1. Visit the ReferralHero iOS SDK repository on GitHub: (https://github.com/maitre-app/ReferralHero-iOS).

2. You can either clone the repository using Git or download the ZIP file directly from GitHub. To clone, use the terminal with the command: `git clone https://github.com/maitre-app/ReferralHero-iOS.git`. If downloading the ZIP, extract it to a known location on your system.

Add Framework to Xcode.

1. Open your Xcode project.

2. Right-click on your project navigator and select "Add Files to [YourProjectName]".

3. Navigate to the location where you cloned or extracted the ReferralHero SDK. You should add the entire `ReferralHero.framework` to your project. Make sure "Copy items if needed" is checked so the framework is copied into your project directory.

Embeded the Framework.

1. Select your project in the Project Navigator to bring up the project settings.

2. Select your target and go to the "General" tab.

3. Scroll down to "Frameworks, Libraries, and Embedded Content".

4. Make sure `ReferralHero.framework` is listed and set to "Embed & Sign". This ensures the framework will be embedded into your app's bundle.

Step: 1

Import and Use the SDK

Import ReferralHero in AppDelegate.swift

import UIKit
import ReferralHero_iOS

If there is no AppDelegate, where @main identifier is present in App function

import SwiftUI
import ReferralHero_iOS

@main
struct Rh_TesteApp: App {

Import ReferralHero in AppDelegate.swift., Or where @main identifier is present in App function.

  • Back in the ReferralHero overview, click to edit your desired Campaign

  • Then the Installation tab, then Mobile App Installation

  • Get your UUID: The 12-letter ID that starts with ‘MF’ in Edit Campaign > launch > Mobile app installation, e.g. MFxxxxxxxxx

Now, you should add The Campaign Token Obtained from the campaign, and UUID from the installation Tab.

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    RHApiKey.configure(
        withAPIKey: "API_TOKEN",
        withuuID: "UUID",
        launchOptions: launchOptions,
        branchKey: "BRANCH_KEY"
    )
    return true
}

This initializes the ReferralHero SDK with Branch.io support for deferred deep linking.

Step 2.

To support universal links through Branch.io:

  1. Open your Xcode project.

  2. Go to TargetSigning & Capabilities.

  3. Click + Capability and select Associated Domains.

  4. Add the following domains:

applinks:yourappname.app.link
applinks:yourappname-alternate.app.link

Replace yourappname with the domain from your Branch.io dashboard.

Step 3.

In the Goal section of your Campaign settings, ensure you have added the Google Play and Apple App Store links and a default referral link for desktop web users.

Well done! You should now be able to build and run your campaign. Before using the more advanced features of the SDK, you should learn about a couple of important concepts.

There are a few major components in the SDK that you can include in your app.

Tracking Referrals

Now that you have implemented the SDK, you can start identifying and tracking referrals!

For that, you will need 2 things:

  1. Universal Link

  2. Your Integrated App

The RH SDK Pulls information from your Device, like this:

RHApiKey.Device = networkManager.getDeviceInfo().modelName
RHApiKey.OS = networkManager.getDeviceInfo().osVersion

With this information, you should be able to add the subscriber data, with the Get Referrer, Add Subscriber, Create Pending Referral, or Track Referral methods to automatically identify or track a referral:

var param = RHSubscriber(
    email: "xyz@gmail.com", //Required value, capture this from user
    domain: "www.abc.com", //Required value, should match the default referral link set within your RH account
    name: “ABC", //Optional but recommended, capture this from user
    referrer: 'referrerCode', // Optional value, Get from the universal link.
    visitorId: sub_********, // Optional value, Get this from the universal link params.
    device: "iPhone", //Required value, see below
    os_type:"iOS", //Required value, see below
    status: "custom_event_pending" //Use 'custom_event_pending' to set the referral status to pending
)

public func formSubmit(param: RHSubscriber){
    WEB_SER.api_POST(endPoint: subscribers, param: param.toDictionary())
    { [self] (result,data) in
        switch result{
            case .success(let response):
            // ...
            case .failure(let err):
            // ...
        }
    }
}

To further understand the implementation of these methods, please check the Public Methods section, and our Github Sample Project.

Last updated