Skip to main content

iOS SDK Reference (Swift)

This page is a comprehensive API reference for the OpenLynk iOS SDK. For a step-by-step integration walkthrough, see the iOS Integration Tutorial.

Installation

The iOS SDK is distributed as a single file:

OpenlynkSDK.swift

Add this file directly to your Xcode project. No package manager setup is required and there are no external dependencies.

OpenlynkSDK Constructor

init(
baseURL: String = "https://openlynk.io",
appId: String,
apiKey: String,
config: OpenlynkSDKConfig = OpenlynkSDKConfig()
)
ParameterTypeRequiredDefaultDescription
baseURLStringNo"https://openlynk.io"API base URL
appIdStringYesYour app ID from the OpenLynk dashboard
apiKeyStringYesYour API key (format: ol_...)
configOpenlynkSDKConfigNoOpenlynkSDKConfig()SDK configuration options

Methods

All methods use completion handlers with Result types.

MethodCompletion TypeDescription
initSDK(completion:)Result<Void, OpenlynkError>Initialize the SDK, send heartbeat, restore pending links
handleIncomingURL(_:completion:)Result<ParsedDeepLink, OpenlynkError>Parse an incoming Universal Link URL
parseDeepLink(url:completion:)Result<ParsedDeepLink, OpenlynkError>Parse a deep link URL manually
createLink(destination:metadata:completion:)Result<CreatedLink, OpenlynkError>Create a shareable deep link
restorePendingLinks(userEmail:completion:)Result<[RestoredLink], OpenlynkError>Restore deferred links by email
restorePendingLinksForAnonymous(completion:)Result<[RestoredLink], OpenlynkError>Restore deferred links using device fingerprint
getLinkBySlug(slug:hostname:completion:)Result<LinkDetails, OpenlynkError>Fetch link details by slug

OpenlynkSDKConfig

struct OpenlynkSDKConfig {
var autoRestoreOnInit: Bool = true
var userEmailProvider: ((@escaping (String?) -> Void) -> Void)? = nil
var onRestoredLinks: (([RestoredLink]) -> Void)? = nil
var onDeepLink: ((ParsedDeepLink) -> Void)? = nil
}
PropertyTypeDefaultDescription
autoRestoreOnInitBooltrueAutomatically restore pending links when initSDK() is called
userEmailProvider((@escaping (String?) -> Void) -> Void)?nilClosure that provides the current user's email asynchronously
onRestoredLinks(([RestoredLink]) -> Void)?nilCallback invoked when deferred links are restored
onDeepLink((ParsedDeepLink) -> Void)?nilCallback invoked when a deep link is parsed

Handling Incoming URLs

:::caution Key Difference from Flutter The iOS SDK does not start an automatic link listener. You must call handleIncomingURL(_:completion:) from your SceneDelegate or AppDelegate when a Universal Link opens your app. :::

SceneDelegate example:

func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
guard let url = userActivity.webpageURL else { return }
openlynkSDK.handleIncomingURL(url) { result in
switch result {
case .success(let deepLink):
// Navigate to deepLink.destinationPath
break
case .failure(let error):
print("Failed to handle URL: \(error)")
}
}
}

OpenlynkError

The SDK defines the following error cases:

enum OpenlynkError: Error {
case invalidURL
case noData
case decodingError
case networkError(Error)
}
CaseDescription
invalidURLThe provided URL could not be parsed
noDataThe API response contained no data
decodingErrorThe API response could not be decoded
networkError(Error)A network-level error occurred (wraps the underlying error)

What's Next?