Skip to content

Repository files navigation

DataPoint iOS SDK

Monetize your app with micro-tasks via the DataPoint iOS SDK.

Installation

Swift Package Manager (Recommended)

Add the following to your Package.swift:

dependencies: [
    .package(url: "https://github.com/trydatapoint/datapoint-ios-sdk.git", from: "1.2.0")
]

Or in Xcode: File → Add Package Dependencies → Enter the repository URL.

Usage

Initialize the SDK

import DataPointSDK

DataPoint.initialize(apiKey: "YOUR_API_KEY") { result in
    switch result {
    case .success:
        print("SDK initialized")
    case .failure(let error):
        print("Failed: \(error)")
    }
}

Set User ID (Optional)

DataPoint.setAppUserId("user123") { result in
    // Handle result
}

Show Tasks

DataPoint.setListener(self)
DataPoint.showTasks(from: viewController)

Check Availability Before Showing an Entry Point (Optional)

DataPoint.checkTaskAvailability { result in
    switch result {
    case .success(let availability):
        earnButton.isHidden = !availability.isAvailable
        // availability.reason: "available" | "no_task" | "daily_limit_reached" | "access_disabled"
        // availability.message: readable form of reason, for your logs
    case .failure(let error):
        // Check could not be made (offline, server error). Decide your own fallback.
        print(error.message, error.code)
    }
}

The answer is exact for this user — the same rules the task wall applies — and the call is read-only on the server. Call it when a screen appears rather than on a timer.

showTasks(from:) runs the same check itself before presenting the screen: when nothing is available you get noTaskAvailable() immediately and no screen is shown. If the check fails or times out (3 s), the screen opens as before.

Implement DataPointListener

extension YourClass: DataPointListener {
    func onTaskCompleted(_ payload: String?) {
        // User completed a task
    }
    
    func onAdRequested() {
        // Show an ad
    }
    
    func noTaskAvailable() {
        // No tasks available
    }
    
    func onClosed() {
        // Task screen closed
    }
    
    func onError(message: String, code: Int) {
        // Handle error
    }

    // Optional: host app went to background / returned while the task UI was visible.
    func onAppLifecycleEvent(_ state: DataPointAppLifecycleState) {
        // .didEnterBackground or .willEnterForeground
    }
}

Opening Links in a Browser

Task pages on DataPoint domains render inside the SDK's WKWebView. Anything else leaves it:

The page does Where it opens
Link / redirect to a non-DataPoint http(s) host In-app SFSafariViewController
target="_blank" link / window.open In-app browser (or the WebView, if the host is DataPoint)
mailto: tel: itms-apps: … The app that handles that scheme
javascript: file: data: about: Blocked

The task screen stays presented underneath, so closing the browser returns the user to their task. If a task completes while the browser is open, the task screen is dismissed once the browser closes. Which target a task's CTA uses (in-app or external) is configured per job in DataPoint, not in your app.

Requirements

  • iOS 13.0+
  • Swift 5.9+

License

Apache License 2.0 - see LICENSE for details.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages