📱 Generate Dynamic Links in iOS
This guide covers how to create a Dynamic Link directly from your iOS app using Swift.
🛠 Prerequisites
Before generating links, ensure:
- Configure ChottuLink Dashboard
- Set up your project
- Configure iOS app settings
- Get your API key
- Install ChottuLink iOS SDK
- Using Swift Package Manager (recommended)
- Or manual installation
- Initialize ChottuLink iOS SDK
- Add initialization code to AppDelegate
- Configure Universal Links
🔗 Build a Dynamic Link
1. Basic link creation
let builder = CLDynamicLinkBuilder(
destinationURL: "https://yourapp.com/content",
domain: "yourapp.chottu.link"
)
.build()
2. Advanced link with all features
let builder = CLDynamicLinkBuilder(
destinationURL: "https://yourapp.com/content",
domain: "yourapp.chottu.link"
)
.setIOSBehaviour(.app)
.setAndroidBehaviour(.browser)
.setLinkName("summer-sale")
.setSelectedPath("promo-summer") // Optional: Customize the URL path
.setSocialParameters( // Optional: Enhance social sharing
title: "Summer Sale",
description: "Check out our amazing deals!",
imageUrl: "https://yourapp.com/images/sale.jpg"
)
.setUTMParameters( // Optional: Track campaign performance
source: "email",
medium: "newsletter",
campaign: "summer2025"
)
.build()
3. Create the Link
Deprecated Method
The completion handler method is deprecated. Use the async version for better performance and error handling.
Recommended: Async Method (v1.0.2+)
Task {
do {
let shortURL = try await ChottuLink.createDynamicLink(for: builder)
print("✅ Created link: \(shortURL)")
// Share the link with your users
} catch {
print("❌ Failed to create link: \(error)")
// Handle the error appropriately
}
}
Legacy: Completion Handler Method
Legacy Method (Deprecated)
ChottuLink.createDynamicLink(for: builder) { link, error in
guard let shortLink = link else {
print("Failed to create link: \(error?.localizedDescription ?? "Unknown error")")
return
}
print("Short Link: \(shortLink)")
}
note
This method is deprecated but still functional. For better performance and error handling, we recommend migrating to the async version above. The legacy method will be removed in a future version.
4. ⚠️ Error Handling
Possible Errors
Note:
The async method can throw various errors. Always implement proper error handling.
ChottuLinkError.notInitialized– If SDK is not initializedChottuLinkError.invalidAPIKey– If the API key is not availableChottuLinkError.missingKeys– If required configuration is missingChottuLinkError.duplicatePath– If the path already existsChottuLinkError.badRequest– If the request is invalid- Network errors if the request fails
info
- Default behavior is set to
.appfor both platforms selectedPathis optional - if not provided, a random path will be generatedsetSocialParametersis optional - enhances link previews when sharedsetUTMParametersis optional - helps track campaign performance- Important: Make sure you have a valid internet connection when creating links
🔄 Link Behaviors
The CLDynamicLinkBehaviour enum controls how your dynamic link behaves on different platforms.
Available Behaviors
enum CLDynamicLinkBehaviour {
case app // Opens the app if installed, falls back to browser
case browser // Always opens in browser
}
tip
Each behavior can be set independently for iOS and Android platforms, allowing for platform-specific user experiences.
Open in App
CLDynamicLinkBehaviour.appHow it works
- Opens your app if installed
- Falls back to browser if app is not installed
- Best for deep linking to specific content
When to Use .app
- Deep linking to specific app content
- Providing seamless user experience
- App functionality is required
Example
.setIOSBehaviour(.app)
Always Browser
CLDynamicLinkBehaviour.browserHow it works
- Always opens in browser
- Useful for marketing campaigns
- Good for analytics tracking
When to Use .browser
- Running marketing campaigns
- Sharing content that works well in browser
- Need consistent analytics tracking
Example
.setIOSBehaviour(.browser)
💡 Best Practices
- Always provide a valid destination URL
- Use meaningful link names for better organization
- Set appropriate platform behaviors
- Include UTM parameters for tracking
- Add social parameters for better sharing
- Test links on both iOS and Android