Nucleus logo
Apple logo

iOS Integration

Installation

1. Download and unzip the file inside https://nucleusanalytics.io/settings once you have created an account and logged in
2. Drag and drop NucleusSDK.xcframework in your project
3. On the Choose options for adding these files screen, make sure your target is checked and Added folders: Create groups is selected before clicking Finish

Import and initial configuration

1. Import NucleusSDK in AppDelegate
2. In the function application include the following fields:

NucleusSDK.publicKey = "<Your-public-key>"
NucleusSDK.idfaMode = .explicit
NucleusSDK.locationMode = .explicit

3. In the function application include the following fields:

private var _nucleusPageSessionId: NucleusSDK.PageSessionId!

// Override viewDidAppear and include the following line:
override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    _nucleusPageSessionId = NucleusSDK.beginPageSession(pageId: "<name-of-the-current-view>", referrerPageId: nil)
}

// Override viewDidDisappear and include the following line:
override func viewDidDisappear(_ animated: Bool) {
    super.viewDidDisappear(animated)
    NucleusSDK.endPageSession(pageSessionId: _nucleusPageSessionId)
}

4. To enable scrollView, include the following in override viewDidAppear:

NucleusSDK.setScrollView(pageSessionId: _nucleusPageSessionId, _tableView)
Engagement configuration

The read-only variable NucleusSDK.engagementInfo exposes engagement info (if available, otherwise nil), with the following fields:

clusterId: String
contentType: String
dayOfWeek: String
genre: String
score: Int
timeOfDay: String
    SwiftUI (only if applicable)

    1. Import NucleusSDK in your main file
    2. Include an AppDelegate file, and in the function application include the following fields:

    NucleusSDK.publicKey = "<Your-public-key>"
    NucleusSDK.idfaMode = .explicit
    NucleusSDK.locationMode = .explicit

    3. Use the @UIApplicationDelegateAdaptor property wrapper to tell SwiftUI to use your AppDelegate created above
    4. Import in your view file including the following:

    private var _nucleusPageSessionId: NucleusSDK.PageSessionId!

    5. Use SwiftUI lifecycle event onAppear with the following:

    _nucleusPageSessionId = NucleusSDK.beginPageSession(pageId: "<name-of-the-current-view>", referrerPageId: nil)
    

    6. Use SwiftUI lifecycle event Disappear with the following:

    NucleusSDK.endPageSession(pageSessionId: _nucleusPageSessionId)