Skip to main content

📱 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:

  1. Configure ChottuLink Dashboard
    • Set up your project
    • Configure iOS app settings
    • Get your API key
  2. Install ChottuLink iOS SDK
    • Using Swift Package Manager (recommended)
    • Or manual installation
  3. Initialize ChottuLink iOS SDK
    • Add initialization code to AppDelegate
    • Configure Universal Links
let builder = CLDynamicLinkBuilder(
destinationURL: "https://yourapp.com/content",
domain: "yourapp.chottu.link"
)
.build()
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()
Deprecated Method

The completion handler method is deprecated. Use the async version for better performance and error handling.

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 initialized
  • ChottuLinkError.invalidAPIKey – If the API key is not available
  • ChottuLinkError.missingKeys – If required configuration is missing
  • ChottuLinkError.duplicatePath – If the path already exists
  • ChottuLinkError.badRequest – If the request is invalid
  • Network errors if the request fails
info
  • Default behavior is set to .app for both platforms
  • selectedPath is optional - if not provided, a random path will be generated
  • setSocialParameters is optional - enhances link previews when shared
  • setUTMParameters is optional - helps track campaign performance
  • Important: Make sure you have a valid internet connection when creating links

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.app

How 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.browser

How 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

✅ Next Steps