All Collections
Onboarding.Online SDK integration
Manual for adding swift-onboarding-sdk to the existing project. UI interface - Storyboard
Manual for adding swift-onboarding-sdk to the existing project. UI interface - Storyboard
O
Written by Onboarding.Online Support Team
Updated over a week ago
  1. Open the required project, go to the dependency settings: “Project -> Package dependency”

    1.1 Click the “+” (Add package dependency) button.

  2. You will see the “Apple swift packages” window.

    Paste the link https://github.com/onboarding-online/swift-onboarding-sdk in the “Search or Enter Package URL” field.

  3. Xcode will show the settings for adding SDK. Make sure the settings look like this “Dependency rule -> branch : main” and click the “Add package” button.

  4. You will see the library verification window. Wait till the verification ends and click “Add package.”


    The package integration has been completed. Only a few code lines remain to be added to your project!

  5. If you use Interface -> Storyboard (Point 6) for the project initializing:
    5.1. Open the AppDelegate file (or wherever you want to add an onboarding launcher: ScreenService).
    5.2 Add to the file header the following:
    import OnboardingiOSSDK
    5.3 Find the function:


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

    }

    5.4 Add the piece of code to it:


    func startOnboarding() {

    let projectId = "projectId"

    // Name of the local JSON file containing onboarding data. Specifying the correct JSON file name is crucial;

    // without it, the onboarding process will not be displayed to the user. This ensures that the onboarding experience

    // is reliably delivered to the user, emphasizing the importance of accurate file naming for a successful onboarding experience.

    let localJSONName = "jsonName"

    // Defines the environment for onboarding. Here, QA (Quality Assurance) is used.

    // .prod (production) is the default value, but QA environment is chosen here for testing purposes.

    let env = OnboardingEnvironment.qa //.prod is the default value

    // Sets a timeout in seconds to wait for a server response before falling back to the local JSON file,

    // ensuring the process continues smoothly with or without stable internet.

    let serverResponseTimeoutForLocalJson = 3.0

    OnboardingService.shared.startOnboarding(projectId: projectId, localJSONFileName: localJSONName, env: env, useLocalJSONAfterTimeout: serverResponseTimeoutForLocalJson) { data in

    switch data {

    case .success(let userInputDict):

    print(userInputDict)

    case .failure(let error):

    print(error.localizedDescription)

    }

    }

    }

  6. If you have already obtained an onboarding.online service project, download the json file of your onboarding Onboarding.online-> project -> onboarding -> json

  7. Drag the file into your Xcode project. After that, a settings window for adding a file will appear.

  8. Select "Copy if needed," "Create groups" and click "Finish."

  9. Add the file name to the onboarding launch function:
    9.1 Open the "AppDelegate" file (or wherever you want to add an onboarding launcher: ScreenService);
    9.2 Add the name of the json file you have downloaded.


    OnboardingService.shared.startOnboarding(projectId: "",

    localJSONFileName: "onboarding-v#1-23",

    useLocalJSONAfterTimeout: 1.0) { data in

    }

  10. Click the run button, wait for the simulator to launch, and enjoy your first onboarding!

 func downloadRecoucesInSeparateFuncThenShowOnboarding() {
/// Identifier for the project, specifying the context for the onboarding process.
let projectId = "0d9a6086-9775-44b6-9888-ae9183d42510"

/// Name of the local JSON file containing onboarding data. Specifying the correct JSON file name is crucial;
/// without it, the onboarding process will not be displayed to the user. This ensures that the onboarding experience
/// is reliably delivered to the user, emphasizing the importance of accurate file naming for a successful onboarding experience.
let localJSONName = "onboarding-v#1"

/// Specifies the environment for onboarding. QA (Quality Assurance) is used here over the default .prod (production) environment
/// for the purpose of testing. It's important to select the appropriate environment to ensure the onboarding process is aligned
/// with the intended user experience and testing conditions.
let env = OnboardingEnvironment.prod // .prod is the default value

/// Sets the timeout in seconds to wait for a server response before using the local JSON. This strategy ensures that
/// the onboarding process can continue smoothly in scenarios of slow or unreliable internet connectivity, highlighting the
/// use of local JSON as both a primary option and a fallback mechanism.
let serverResponseTimeoutForLocalJson = 3.0


/// This is an optional method for optimizing UX; it allows you to download resources in advance so that at the moment of starting the onboarding,
/// the user does not have to wait for the resources to be downloaded.
/// To use the results of the downloaded resources, use the paired method:
/// startPreparedOnboardingWhenReady(projectId: projectId, localJSONFileName: localJSONName, env: env, useLocalJSONAfterTimeout: serverResponseTimeoutForLocalJson)

// OnboardingService.prepareFullOnboardingFor(projectId: projectId, localJSONFileName: localJSONName) {_ in
// print("assets has been loaded")
// }

/// Initiates the onboarding process with the specified parameters: project ID, local JSON file name, environment, and
/// server response timeout. The precise naming of the local JSON file is crucial for the successful display of the onboarding,
/// ensuring that users receive the intended experience even in the absence of server connectivity.
OnboardingService.shared.startPreparedOnboardingWhenReady(projectId: projectId, localJSONFileName: localJSONName, env: env, useLocalJSONAfterTimeout: serverResponseTimeoutForLocalJson) { [weak self] data in
switch data {
case .success(let userInputDict):
self?.showRegularFlow()
print(userInputDict)
case .failure(let error):
print(error.localizedDescription)
self?.showRegularFlow()
}
}
}

11. To connect analytics, implement the callback created for the transfer of events and user parameters from the SDK to your analytics system.

func catchAnalyticsEvents() {

OnboardingService.shared.userEventListener = {(data, params) in

print("\(data.rawValue) params \(params ?? [:])")

//Amplitude.instance().logEvent(data.rawValue, withEventProperties: params)

}

OnboardingService.shared.systemEventListener = {(data, params) in

print("\(data.rawValue) params \(params ?? [:])")

//Amplitude.instance().logEvent(data.rawValue, withEventProperties: params)

}

}

12. If you want to manage requests for push notifications and ATT, implement the callback.

func requestPermission() {

OnboardingService.shared.permissionRequestCallback = {(screen, permissionType) in

switch permissionType {

case .notifications:

/// implement push notification request

print(permissionType.rawValue)

case .ads:

/// implement push trqcking request

print(permissionType.rawValue)

}

}

}

13. To enable custom screens, implement the callback for custom screens.

func handleCustomScreen() {

/// You can display your own screens and also use the parameters entered by the user on them for conditional transitions.

/// For example, you can show an authentication screen or a paywall, and pass on which purchase the user selected,

/// and based on that, direct them along the appropriate branch of transitions in the onboarding.

OnboardingService.shared.customFlow = { (screen, navigationController) in

if screen.name == "paywall" {

///Initialize your UIViewController

let controller = TestCustomController.instantiateWith(customScreen: screen, inputValue: ["price": "29.99"])

/// Set your controller as the sole controller of the UINavigationController provided by the SDK.

navigationController?.viewControllers = [controller]

controller.dismissalHandler = {(userInputValueForCondition) in

/// After implementing the logic of your controller, you need to call a method that will return screen management to the SDK.

/// You can pass the values obtained on your controller in order to use these values for conditional transitions on the onboarding screen.

///

OnboardingService.shared.customFlowFinished(customScreen: screen, userInputValue: userInputValueForCondition)

}

}

}

}

14. If you want to show a paywall outside of onboarding, use this approach.

func showPaywallWithoutOnboarding() {

let projectID = "your_project_id"

let jsonName = "your_json_name"

OnboardingService.shared.paymentService = OnboardingPaymentService(sharedSecret: "835abc10bd3545ad8621fe26095762f6")

//showLoadingIndicator()

let env = envMode()

OnboardingService.shared.getPaywall(paywallId: "screen1", projectId: projectID, localJSONFileName: jsonName, env: .prod, useLocalJSONAfterTimeOut: 20) { [weak self] result in

//self?.hideLoadingIndicator()

switch result {

case .success(let paywall):

paywall.closePaywallHandler = { (controller) in

self?.navigationController?.popViewController(animated: true)

}

paywall.purchaseHandler = { (controller, receipt) in

self?.navigationController?.popViewController(animated: true)

}

self?.navigationController?.pushViewController(paywall, animated: true)

case .failure(let error):

print(error.localizedDescription)

}

}


Did this answer your question?