Documentation Index
Fetch the complete documentation index at: https://docs.pnlight.app/llms.txt
Use this file to discover all available pages before exploring further.
Use the Swift SDK for native iOS apps.
Requirements
- iOS 13.0+
- Swift 5.7+
- Swift Package Manager
Install with Swift Package Manager
Add the package to Package.swift:
dependencies: [
.package(url: "https://github.com/pnlight-dev/sdk-swift.git", from: "0.2.1")
]
Or add it in Xcode:
Open package settings
In Xcode, click File and then Add Packages….
Enter the repository URL
Enter https://github.com/pnlight-dev/sdk-swift.git.
Select a version
Select the version you want to use and add the package to your app target.
Initialize the SDK
Call initialization during app startup.
import PNLightSDK
await PNLightSDK.shared.initialize(apiKey: "pnlight_sdk_token")
Common calls
let userId = PNLightSDK.shared.getUserId()
let isAllowed = await PNLightSDK.shared.validatePurchase()
await PNLightSDK.shared.logEvent("purchase_completed", eventArgs: [
"product_id": "premium_subscription",
"amount": 9.99
])
await PNLightSDK.shared.addAttribution(
provider: .appsFlyer,
data: ["af_status": "Non-organic"],
identifier: "appsFlyerCustomerId"
)
Server-driven UI
Use RemoteUiView in SwiftUI when you want PNLight to render a configured placement.
import PNLightSDK
import SwiftUI
struct PaywallScreen: View {
var body: some View {
RemoteUiView(placement: "paywall", cardId: "paywall_card") { action in
if action.logId == "purchase_button" {
let productId = action.params["id"] ?? ""
Task { await purchase(productId) }
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
}
To reduce visible loading time, prefetch the config before you present the screen:
PNLightSDK.shared.prefetchUIConfig(placement: "paywall")
See server-driven UI for placement and action guidance.