Skip to main content

iOS SDK Setup

AppsOnAir-AppLink helps you manage deep links and in-app routing seamlessly in your iOS app. With a simple integration, you can configure, manage, and respond to links from the web dashboard in real time.

BETA

The plugin is fully functional and integrates with our AppLink service, which is currently in public beta. While you can start using it today, please note that there may be minor changes or improvements as we prepare for full production launch.

Basic Requirements

apiKey Setup
  • Ensure that your API key is correctly configured. For more information, refer to the Getting Started guide.
Prerequisites
  • Minimum supported deployment target is iOS 13.0.

Import the SDK into Your Xcode Project

Using CocoaPods

2.1 Close your Xcode project if it’s open.

2.2 In your project’s root directory, run the following command to install CocoaPods:

Terminal
sudo gem install cocoapods

2.3 Run the following command to initialize CocoaPods:

Terminal
pod init

2.4 Open the generated Podfile in your preferred code editor and add the SDK dependency under your app target:

Podfile
target 'your_project_name' do
pod 'AppsOnAir-AppLink'
end

2.5 In the terminal, navigate to your project directory and run:

Terminal
pod repo update
pod install

Configure Entitlements and URL Schemes

Note
  • Configuring associated domains is optional.
  • In Xcode, Under TARGETS, select your app target (usually the one named after your app).
  • At the top, select the Signing & Capabilities tab.
  • Click the + Capability button in the top-left corner of that section.
  • In the list of capabilities, scroll or search to select Associated Domains.
  • This will automatically create a file named YOUR_PROJECT.entitlements.

Associated Domains

Create or update the YOUR_PROJECT.entitlements file and add the following:

YOUR_PROJECT.entitlements
<!-- If Using Universal Links -->
<key>com.apple.developer.associated-domains</key>
<array>
<string>applinks:YOUR_DOMAIN</string> <!-- Replace with your actual domain -->
</array>

Add/Update Associated Domain

Docusaurus logo

Note

After configuring the Associated Domain for Universal Links, it may take up to 24 hours for the changes to be reflected and become active. The Associated Domain setup and verification process is managed by Apple.

Custom URL Scheme

If you're using a Custom URL scheme, update your app’s Info.plist file with the following:

Info.plist
<!-- If Using Custom Url Schema -->
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>YOUR_URL_NAME</string>
<key>CFBundleURLSchemes</key>
<array>
<string>YOUR_CUSTOM_URL_SCHEME</string> <!-- Replace with your custom URL scheme -->
</array>
</dict>
</array>

Import the SDK at the top of your AppDelegate file or relevant Swift/SwiftUI/Objective-C file:

AppDelegate.swift
import AppsOnAir_AppLink

Implementation

AppDelegate.swift
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?
let appOnAirLinkService = AppLinkService.shared

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Initialize the link service
appOnAirLinkService.initialize { url,linkInfo in
// Handle the link and its associated data here
}
return true
}

}
Important

When using SwiftUI, it is necessary to add the .onOpenURL modifier in ContentView.swift, directly after any layout container such as VStack, Button, or similar views for handling AppLink.

VStack {
// Your UI components here
}
.onOpenURL { url in
AppLinkService.shared.handleAppLink(incomingURL: url)
}
  • The initialize() function initializes the common AppLink service and sets up the deep link handler. It processes the incoming link when the app is launched with any URL.

You can also generate a AppLink such as from a button tap within your application’s UI.

Import the SDK

Import the AppsOnAir_AppLink module into your ViewController or relevant Swift/SwiftUI/Objective-C file.

ViewController.swift
import AppsOnAir_AppLink
ViewController.swift
class ViewController: UIViewController {
let appOnAirLinkService = AppLinkService.shared

override func viewDidLoad() {
super.viewDidLoad()

let button = UIButton(type: .system)
button.setTitle("Button", for: .normal)
button.backgroundColor = .systemBlue
button.setTitleColor(.white, for: .normal)
button.layer.cornerRadius = 10

// Set button frame (size and position)
button.frame = CGRect(x: 100, y: 200, width: 150, height: 50)

// Add target for onPressed (TouchUpInside)
button.addTarget(self, action: #selector(buttonPressed), for: .touchUpInside)

// Add the button to the view
self.view.addSubview(button)
}

// Define the action when button is pressed
@objc func buttonPressed() {
// Help to create the link
// <urlPrefix> shouldn't contain http or https
appOnAirLinkService.createAppLink(url: "https://example.com",name: "YOUR_LINK_NAME",urlPrefix: "YOUR_DOMAIN_NAME",shortId: "LINK_ID",socialMeta: [:],isOpenInBrowserApple: false,isOpenInIosApp: true,iOSFallbackUrl: "",isOpenInAndroidApp: true,isOpenInBrowserAndroid: false,androidFallbackUrl: ""
) { linkInfo in
//write the code for handling create link
}
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}

AppLinkParams Properties

Defines all parameters used to construct a AppLink, including app URL, fallbacks, short ID, and social-meta.

KeyDescription
urlThe actual deep link URL that the app should open. Example: myapp://product/123
nameThe name or label for the link, often used for internal identification.
urlPrefixThe base URL prefix for the link (e.g., https://app.domain.com/). This helps create a complete shareable link.
androidFallbackUrlA web URL to redirect users to when the app is not installed on Android devices.
iOSFallbackUrlA web URL to redirect users to when the app is not installed on iOS devices.
shortIdAn optional short ID to make the link shorter and easier to share. If provided, the final link becomes urlPrefix/shortId
socialMetaMeta information used for social sharing previews. refer SocialMeta Properties
isOpenInBrowserAppleDetermines whether the link should open in the browser on Apple devices (iOS/macOS).
isOpenInIosAppSpecifies if the link should open in the iOS app even if your app is installed.
isOpenInAndroidAppIndicates whether to open the link in the Android app even if your app is installed.
isOpenInBrowserAndroidDetermines if the link should open in the browser on Android devices.

socialMeta Properties

KeyDescription
titleThe title to show in social media link previews.
descriptionA short description used in social sharing cards (Facebook, Twitter, etc.).
imageUrlA URL to an image that will appear in the social media preview.

You can also retrieving linkInfo, such as from a button action:

Import the SDK

Import the AppsOnAir_AppLink module into your ViewController.swift or relevant Swift/Objective-C file.

ViewController.swift
import AppsOnAir_AppLink
ViewController.swift
class ViewController: UIViewController {
let appOnAirLinkService = AppLinkService.shared

override func viewDidLoad() {
super.viewDidLoad()

let button = UIButton(type: .system)
button.setTitle("Button", for: .normal)
button.backgroundColor = .systemBlue
button.setTitleColor(.white, for: .normal)
button.layer.cornerRadius = 10

// Set button frame (size and position)
button.frame = CGRect(x: 100, y: 200, width: 150, height: 50)

// Add target for onPressed (TouchUpInside)
button.addTarget(self, action: #selector(buttonPressed), for: .touchUpInside)

// Add the button to the view
self.view.addSubview(button)
}

// Define the action when button is pressed
@objc func buttonPressed() {
// Help to retrieving referral linkInfo
appOnAirLinkService.getReferralDetails { linkInfo in
//write the code for handling referral linkInfo
}
}


override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

}
Response
{
"message": "Referral link fetched successfully!",
"status": "SUCCESS",
"data": {
"link": "https://your.link",
"name": "AppLink",
"referralLink": "https://your.referral.link",
"shortId": "linkId",
"socialMetaTags": {
"description": "Description",
"imageUrl": "https://example.xom",
"title": "Meta Title"
}
}
}

Troubleshooting

If your app isn’t handling Universal Links or Deep Links as expected, ensure that you’ve correctly implemented the required delegate methods in both AppDelegate and SceneDelegate.

AppDelegate Setup

AppDelegate.swift
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?
let appOnAirLinkService = AppLinkService.shared

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
guard userActivity.activityType == NSUserActivityTypeBrowsingWeb,
let url = userActivity.webpageURL else {
return false
}
appOnAirLinkService.handleAppLink(incomingURL: url)
return true
}

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
appOnAirLinkService.handleAppLink(incomingURL: url)
return true
}
}

SceneDelegate Setup

SceneDelegate.swift
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
let appOnAirLinkService = AppLinkService.shared
var window: UIWindow?

func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
guard let urlContext = URLContexts.first else { return }
let url = urlContext.url
appOnAirLinkService.handleAppLink(incomingURL: url)
}
func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
guard userActivity.activityType == NSUserActivityTypeBrowsingWeb,
let incomingURL = userActivity.webpageURL else {
return
}
appOnAirLinkService.handleAppLink(incomingURL: incomingURL)
}
}
note

For testing purposes:

  • Click the referral link, it should redirect you to the App Store.
  • To retrieve the latest referral data, you must uninstall the app, then reinstall it, and fetch the referral again.

Run your app by using Xcode on iOS simulators or any physical device to make sure it builds correctly.

For more details explore the example