import Bit2ConnectSDKclass AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Initialize Bit2Connect SDK Bit2ConnectSDK.shared.initialize( baseURL: "https://api.bit2connect.com", apiKey: "your-api-key-here", debugMode: true ) // Handle deferred deep link on app launch Bit2ConnectSDK.shared.handleDeferredDeepLink { result in switch result { case .success(let linkData): print("Deferred deep link found: \(linkData.originalUrl)") self.handleLinkData(linkData) case .noLink: print("No deferred deep link found") case .error(let message): print("Error getting deferred deep link: \(message)") } } return true } func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool { // Handle direct deep link Bit2ConnectSDK.shared.handleDirectDeepLink(url: url) { result in switch result { case .success(let linkData): print("Direct deep link handled: \(linkData.originalUrl)") self.handleLinkData(linkData) case .error(let message): print("Error handling direct deep link: \(message)") } } return true } private func handleLinkData(_ linkData: LinkData) { // Process the link data print("Processing link data:") print("- Original URL: \(linkData.originalUrl)") print("- Path: \(linkData.path)") print("- Campaign: \(linkData.campaign ?? "None")") print("- Source: \(linkData.source ?? "None")") print("- Medium: \(linkData.medium ?? "None")") print("- Parameters: \(linkData.parameters)") // Navigate to appropriate screen based on link data if let campaign = linkData.campaign { navigateToContent(campaign: campaign, parameters: linkData.parameters) } } private func navigateToContent(campaign: String, parameters: [String: String]) { // Implement your navigation logic here // Example: Navigate to a specific product page if let productId = parameters["product_id"] { NotificationCenter.default.post( name: NSNotification.Name("NavigateToProduct"), object: nil, userInfo: ["productId": productId] ) } }}
Handle deferred deep links when the app is launched.Parameters:
completion (Closure): Completion handler with result
Example:
Bit2ConnectSDK.shared.handleDeferredDeepLink { result in switch result { case .success(let linkData): // Process deferred deep link case .noLink: // No deferred link found case .error(let message): // Handle error }}
Handle direct deep links when the app is already installed.Parameters:
url (URL): The deep link URL to process
completion (Closure): Completion handler with result
Example:
Bit2ConnectSDK.shared.handleDirectDeepLink(url: url) { result in switch result { case .success(let linkData): // Process direct deep link case .error(let message): // Handle error }}
You can test your integration using the Bit2Connect dashboard or API:
// Test with a sample dynamic linklet testLink = URL(string: "https://b2co.link/abc12345")!Bit2ConnectSDK.validateLink(testLink) { isValid, linkData in if isValid { print("Link is valid: \(linkData?.shortUrl ?? "")") } else { print("Link is invalid") }}
Solution: Ensure your app is properly configured for deep linking and
the SDK is initialized before handling links.
iOS links not working
Solution: Verify that your iOS app’s URL scheme is correctly configured in
Info.plist and that the app is properly signed.
App not opening from links
Solution: Check that your app is properly configured as a URL scheme
handler and that the links are correctly formatted.
Swift Package Manager import errors
Solution: Ensure you’re using the correct import syntax and that the
package is properly added to your target. For Package.swift, use: swift dependencies: [.product(name: "Bit2ConnectSDK", package: "bit2connect-ios-sdk")]
Build errors with SPM
Solution: Make sure your project’s iOS deployment target is 13.0 or higher,
and that you’re using Swift 5.0+. Try cleaning your build folder and rebuilding.
private func handleLinkData(_ linkData: LinkData) { // Process the link data based on campaign and parameters if let campaign = linkData.campaign { switch campaign { case "product": if let productId = linkData.parameters["product_id"] { navigateToProduct(productId) } case "category": if let categoryId = linkData.parameters["category_id"] { navigateToCategory(categoryId) } case "promotion": if let promoCode = linkData.parameters["promo_code"] { navigateToPromotion(promoCode) } default: break } }}private func navigateToProduct(_ productId: String) { let storyboard = UIStoryboard(name: "Main", bundle: nil) if let productVC = storyboard.instantiateViewController(withIdentifier: "ProductViewController") as? ProductViewController { productVC.productId = productId navigationController?.pushViewController(productVC, animated: true) }}
private func handleLinkData(_ linkData: LinkData) { // Process the link data based on campaign and parameters if let campaign = linkData.campaign { switch campaign { case "post": if let postId = linkData.parameters["post_id"] { navigateToPost(postId) } case "profile": if let userId = linkData.parameters["user_id"] { navigateToProfile(userId) } default: break } }}private func navigateToPost(_ postId: String) { let storyboard = UIStoryboard(name: "Main", bundle: nil) if let postVC = storyboard.instantiateViewController(withIdentifier: "PostViewController") as? PostViewController { postVC.postId = postId navigationController?.pushViewController(postVC, animated: true) }}