The ULink iOS SDK provides a comprehensive solution for creating, managing, and handling deep links in iOS applications.
- Dynamic Link Creation: Create dynamic links with customizable parameters
- Unified Link Creation: Create unified links with platform-specific URLs
- Deep Link Resolution: Resolve and handle incoming deep links
- Session Management: Automatic session tracking with app lifecycle handling
- Installation Tracking: Track app installations and user analytics
- Universal Link Support: Handle both custom URL schemes and universal links
- Persistence: Optional persistence of last resolved link data
- Combine Integration: Reactive streams for link resolution events
- iOS 13.0+
- Swift 5.0+
- Xcode 12.0+
Add the following to your Podfile
:
pod 'ULinkSDK', '~> 1.0.0'
Then run:
pod install
Add the following to your Package.swift
:
dependencies: [
.package(url: "https://github.com/ulink/ios-sdk.git", from: "1.0.0")
]
In your AppDelegate.swift
:
import ULinkSDK
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let config = ULinkConfig(
apiKey: "your-api-key-here",
baseUrl: "https://api.ulink.com",
debug: true,
enableDeepLinkIntegration: true,
persistLastLinkData: true
)
let ulink = ULink.initialize(config: config)
// Handle link resolution
ulink.onLink.sink { resolvedData in
print("Resolved link: \(resolvedData.slug ?? "unknown")")
// Handle the resolved link data
}.store(in: &cancellables)
return true
}
Add URL handling in your AppDelegate.swift
:
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
return ULink.shared.handleIncomingURL(url)
}
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
guard userActivity.activityType == NSUserActivityTypeBrowsingWeb,
let url = userActivity.webpageURL else {
return false
}
return ULink.shared.handleIncomingURL(url)
}
let parameters = ULinkParameters.dynamic(
slug: "my-dynamic-link",
iosFallbackUrl: "https://apps.apple.com/app/myapp",
androidFallbackUrl: "https://play.google.com/store/apps/details?id=com.myapp",
fallbackUrl: "https://myapp.com",
parameters: ["userId": "12345", "campaign": "summer2024"],
socialMediaTags: SocialMediaTags(
title: "Check out this awesome app!",
description: "Download our app for the best experience",
imageUrl: "https://myapp.com/share-image.png"
)
)
Task {
do {
let response = try await ULink.shared.createLink(parameters: parameters)
print("Created link: \(response.url ?? "No URL")")
} catch {
print("Error creating link: \(error.localizedDescription)")
}
}
let parameters = ULinkParameters.unified(
slug: "my-unified-link",
iosUrl: "myapp://content/123",
androidUrl: "myapp://content/123",
fallbackUrl: "https://myapp.com/content/123"
)
Task {
do {
let response = try await ULink.shared.createLink(parameters: parameters)
print("Created unified link: \(response.url ?? "No URL")")
} catch {
print("Error creating unified link: \(error.localizedDescription)")
}
}
// Using Combine
ULink.shared.onLink.sink { resolvedData in
// Handle dynamic links
if let slug = resolvedData.slug {
navigateToContent(slug: slug, parameters: resolvedData.parameters)
}
}.store(in: &cancellables)
ULink.shared.onUnifiedLink.sink { resolvedData in
// Handle unified links
if let iosUrl = resolvedData.iosUrl {
handleDeepLink(url: iosUrl)
}
}.store(in: &cancellables)
// Get last resolved link
if let lastLink = ULink.shared.getLastLinkData() {
print("Last resolved link: \(lastLink.slug ?? "unknown")")
}
The ULinkConfig
class provides various configuration options:
let config = ULinkConfig(
apiKey: "your-api-key", // Required: Your ULink API key
baseUrl: "https://api.ulink.com", // API base URL
debug: true, // Enable debug logging
enableDeepLinkIntegration: true, // Enable automatic deep link handling
persistLastLinkData: true, // Persist last resolved link
lastLinkTimeToLive: 3600, // TTL for persisted link (seconds)
clearLastLinkOnRead: false, // Clear link data after reading
redactAllParametersInLastLink: false, // Redact all parameters in persisted link
redactedParameterKeysInLastLink: ["token"] // Specific keys to redact
)
Add URL schemes to your app's Info.plist
:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>com.yourapp.deeplink</string>
<key>CFBundleURLSchemes</key>
<array>
<string>yourapp</string>
<string>ulink</string>
</array>
</dict>
</array>
For universal links, add associated domains to your app's entitlements:
<key>com.apple.developer.associated-domains</key>
<array>
<string>applinks:yourdomain.com</string>
<string>applinks:*.yourdomain.com</string>
</array>
The SDK automatically manages sessions based on app lifecycle:
// Check current session
if ULink.shared.hasActiveSession() {
print("Session ID: \(ULink.shared.getCurrentSessionId() ?? "none")")
}
// Get session state
let state = ULink.shared.getSessionState()
print("Session state: \(state)")
The SDK provides specific error types:
do {
let response = try await ULink.shared.createLink(parameters: parameters)
} catch ULinkError.notInitialized {
print("SDK not initialized")
} catch ULinkError.invalidConfiguration {
print("Invalid configuration")
} catch ULinkError.networkError {
print("Network error")
} catch {
print("Other error: \(error.localizedDescription)")
}
The SDK includes a test app demonstrating all features. To run the test app:
- Open the project in Xcode
- Select the
ULinkSDKExample
target - Update the API key in
AppDelegate.swift
- Build and run
Main SDK class providing all functionality.
initialize(config:)
- Initialize the SDKcreateLink(parameters:)
- Create a dynamic or unified linkresolveLink(url:)
- Resolve a ULink URLhandleIncomingURL(_:)
- Handle incoming URLsgetLastLinkData()
- Get last resolved link dataclearLastResolvedLink()
- Clear persisted link data
onLink
- Publisher for dynamic link resolution eventsonUnifiedLink
- Publisher for unified link resolution eventsisInitialized
- Whether SDK is initialized
Configuration class for SDK initialization.
Parameters for link creation with factory methods:
dynamic(...)
- Create dynamic link parametersunified(...)
- Create unified link parameters
Data structure for resolved link information.
MIT License. See LICENSE file for details.
For support, please contact [email protected] or visit our documentation at https://docs.ulink.com