iOS - Using Third-Party SDKs
The Mobile SDK Module swift package architecture enables you to enhance the Q2 Mobile Application using modular, native iOS components. While designing your module, you may need to incorporate third-party Swift packages to extend functionality—whether for networking, analytics, data processing, or other utilities.
This guide explains how to safely and effectively integrate third-party Swift libraries within your module, using two supported methods:
There are two supported ways to include third-party libraries:
1. Package dependency using swift package repository URL
You can declare publicly available swift packages hosted on Git-based repositories
directly in your module’s Package.swift
file.
Example
Let's assume you are building Mobile SDK Module swift package named q2-demo-ios
and you
want to add Alamofire
then,
Step 1: Update Package.swift
of q2-demo-ios
dependencies section:
dependencies: [
.package(url: "https://github.com/Alamofire/Alamofire.git", from: "5.6.0")
]
Step 2: Update q2-demo-ios
target,
.target(
name: "q2-demo-ios",
dependencies: [
...
.product(
name: "Alamofire",
package: "Alamofire"
),
...
],
path: "q2-demo-ios/Sources/Q2Demo",
...
)
Final Package.swift
would look like follow:
// swift-tools-version: 5.8
import PackageDescription
let package = Package(
name: "q2-demo-ios",
...
products: [
.library(
name: "Q2Demo",
targets: [
"q2-demo-ios"
]
),
],
dependencies: [
....
.package(
url: "https://github.com/Alamofire/Alamofire.git",
exact: "5.6.0"
),
...
],
targets: [
.target(
name: "q2-demo-ios",
dependencies: [
...
.product(
name: "Alamofire",
package: "Alamofire"
),
...
],
path: "q2-demo-ios/Sources/Q2Demo",
...
),
....
]
)
2. Using Binary .xcframework Files
For closed-source or binary-only libraries, you may include precompiled .xcframework files directly in the module.
Steps:
Example
Let's assume you are building Mobile SDK Module swift package named q2-demo-ios
and you
want to add ThirdPartyXCFramework
(third-party xcframework) then,
Step 1: Place all .xcframework files into the Frameworks
directory within your
module folder
Update Package.swift
of q2-demo-ios
dependencies section:
.binaryTarget(
name: "ThirdPartyXCFramework",
path: "q2-demo-ios/Frameworks/ThirdPartyXCFramework.xcframework"
)
Update q2-demo-ios
target,
.target(
name: "q2-demo-ios",
dependencies: [
...
.product(
name: "Alamofire",
package: "Alamofire"
),
...
],
path: "q2-demo-ios/Sources/Q2Demo",
...
)
Final Package.swift
would look like follow:
// swift-tools-version: 5.8
import PackageDescription
let package = Package(
name: "q2-demo-ios",
...
products: [
.library(
name: "Q2Demo",
targets: [
"q2-demo-ios"
]
),
],
dependencies: [
...
],
targets: [
.target(
name: "q2-demo-ios",
dependencies: [
.product(
name: "Q2ModuleInterfaces",
package: "q2-mobile-ios"
),
...
"ThirdPartyXCFramework"
...
],
path: "q2-demo-ios/Sources/Q2Demo",
...
),
.binaryTarget(
name: "ThirdPartyXCFramework",
path: "q2-demo-ios/Frameworks/ThirdPartyXCFramework.xcframework"
)
]
)
➡️ Once your resources are configured, you can move on to Resources in Module to declare your module in the app runtime.