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

Manually

Step 1.

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.

Step 2.

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.

Step 2.

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 3.

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 {

Step 4.

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. MF15298bba6d

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 {
        // Override point for customization after application launch.
   
        RHApiKey.configure(withAPIKey: "API_TOKEN", withuuID: "UUID")
        return true
    }

Step 5.

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:

networkManager.getPublicIPAddress { IP in
    if let ipAddress = IP {
        RHApiKey.IP = ipAddress
        print("getPublicIPAddress.\(ipAddress)")
        } else {
            print("Unable to fetch the public IP address.")
        }
}
RHApiKey.Device = networkManager.getDeviceInfo().modelName
RHApiKey.OS = networkManager.getDeviceInfo().osVersion
RHApiKey.SCREEN_SIZE = networkManager.getScreenSize()

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:

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