Skip to main content

iOS Native Integration

Use the iOS SDK to collect native app events, request IDFA permission, support universal links, and send metadata from Swift applications.

Install with CocoaPods

Add the SDK to your Podfile:

pod 'DriveMetaDataiOSSDK'

Install dependencies:

pod install

Open the generated .xcworkspace file after installation.

Import the SDK

import DriveMetaDataiOSSDK

Initialize the SDK

Initialize in AppDelegate from application(_:didFinishLaunchingWithOptions:):

DriveMetaData.initializeShared(
clientId: <DMD_CLIENT_ID>,
clientToken: "<DMD_CLIENT_TOKEN>",
clientAppId: <DMD_CLIENT_APP_ID>
)
ParameterDescription
clientIdDriveMetaData client identifier.
clientTokeniOS client token provisioned for the app.
clientAppIdDriveMetaData application identifier.

Do not embed server tokens in iOS application code.

Request IDFA Permission

For iOS 14 and later, request App Tracking Transparency permission when your product flow allows it:

DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
DriveMetaData.shared?.requestIDFA()
}

Add NSUserTrackingUsageDescription to Info.plist:

<key>NSUserTrackingUsageDescription</key>
<string>We use your data to provide a personalized experience and show relevant ads.</string>

Send Metadata

let userDetails: [String: Any] = [
"userDetails": [
"first_name": "Amit",
"last_name": "Gupta",
"mobile": "+15555550123"
],
"userIdentifier": [
"email": "[email protected]"
]
]

DriveMetaData.shared?.sendTags(tags: userDetails, eventType: "user_registration") { response in
print("Received response: \(response)")
}

Avoid sending secrets, payment card data, passwords, or unapproved sensitive fields.

Add Associated Domains in Xcode:

  1. Open the Xcode project.
  2. Go to Signing & Capabilities.
  3. Add Associated Domains.
  4. Add domains using the applinks: prefix:
applinks:<yourdomain>.com

Handle universal links in SceneDelegate.swift:

import UIKit
import DriveMetaDataiOSSDK

class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?

func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
guard userActivity.activityType == NSUserActivityTypeBrowsingWeb,
let url = userActivity.webpageURL else {
return
}

DriveMetaData.shared?.getBackgroundData(uri: url) { jsonString, error in
if let error = error {
print("Error: \(error.localizedDescription)")
} else if let jsonString = jsonString {
print("DMD received data: \(jsonString)")
}
}
}
}

Handle custom URL schemes in AppDelegate.swift when required:

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

Device and App Details

Use SDK helpers during integration testing:

print("Device Details", DriveMetaData.shared?.deviceDetails() ?? "No Data")
print("App Details", DriveMetaData.shared?.appDetails() ?? "No Data")

Production Checklist

  • Initialize once during app launch.
  • Use iOS client credentials only.
  • Add ATT usage text before requesting IDFA.
  • Add Associated Domains for universal links.
  • Validate event names and payload schemas.
  • Test cold start, background, foreground, universal link, and custom URL flows.