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()
)
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
baseURL | String | No | "https://openlynk.io" | API base URL |
appId | String | Yes | — | Your app ID from the OpenLynk dashboard |
apiKey | String | Yes | — | Your API key (format: ol_...) |
config | OpenlynkSDKConfig | No | OpenlynkSDKConfig() | SDK configuration options |
Methods
All methods use completion handlers with Result types.
| Method | Completion Type | Description |
|---|---|---|
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
}
| Property | Type | Default | Description |
|---|---|---|---|
autoRestoreOnInit | Bool | true | Automatically restore pending links when initSDK() is called |
userEmailProvider | ((@escaping (String?) -> Void) -> Void)? | nil | Closure that provides the current user's email asynchronously |
onRestoredLinks | (([RestoredLink]) -> Void)? | nil | Callback invoked when deferred links are restored |
onDeepLink | ((ParsedDeepLink) -> Void)? | nil | Callback 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)
}
| Case | Description |
|---|---|
invalidURL | The provided URL could not be parsed |
noData | The API response contained no data |
decodingError | The API response could not be decoded |
networkError(Error) | A network-level error occurred (wraps the underlying error) |
Related Pages
- Data Types Reference — full field-level documentation for
CreatedLink,ParsedDeepLink,RestoredLink, andLinkDetails - iOS Integration Tutorial — step-by-step guide to integrating the SDK
- iOS Universal Links Guide — configure Universal Links for your app
What's Next?
- Configure Universal Links so deep links open your app
- Learn how to handle deep links in your iOS app
- Implement deferred deep linking for users who install after clicking a link