This SDK allows you to create short links using the Short.io API based on a public API key and custom parameters. It also supports iOS deep linking integration using Universal Links.
- Generate short links via Short.io API
- Customize short links using parameters
- Integrate iOS Universal Links (Deep Linking)
- Simple and clean API for developers
You can integrate the SDK into your Xcode project using Swift Package Manager (SPM) or Manual Installation.
To install the SDK via Swift Package Manager:
- Open your Xcode project.
- Go to File > Add Packages Dependencies
- In the search bar, paste the SDKβs GitHub repository URL:
https://github.com/Short-io/ios-sdk/
- Choose the latest version or a specific branch.
- Click Add Package.
- Import the SDK where needed:
import ShortIOSDK
If you prefer to install the SDK manually:
- Clone or download the SDK repository.
- Open your Xcode project.
- Go to File > Add Packages Dependencies
- Click the Add Local Package button.
- Select the downloaded SDK folder.
- Click Add Package.
- Visit Short.io and sign up or log in to your account.
- In the dashboard, navigate to Integrations & API.
- Click CREATE API KEY button.
- Enable the Public Key toggle.
- Click CREATE to generate your API key.
import ShortIOSDK
let sdk = ShortIOSDK()
let parameters = ShortIOParameters(
domain: "your_domain", // Replace with your Short.io domain
originalURL: "your_originalURL"// Replace with your Short.io domain
)
Note: Both domain
and originalURL
are the required parameters. You can also pass optional parameters such as path
, title
, utmParameters
, etc.
let apiKey = "your_public_apiKey" // Replace with your Short.io Public API Key
Task {
do {
let result = try await sdk.createShortLink(
parameters: parameters,
apiKey: apiKey
)
switch result {
case .success(let response):
print("Short URL created: \(response.shortURL)")
case .failure(let errorResponse):
print("Error occurred: \(errorResponse.message), Code: \(errorResponse.code ?? "N/A")")
}
} catch {
print("Error: \(error.localizedDescription)")
}
}
The ShortIOParameters
struct is used to define the details of the short link you want to create. Below are the available parameters:
Parameter | Type | Required | Description |
---|---|---|---|
domain |
String |
β | Your Short.io domain (e.g., example.short.gy ) |
originalURL |
String |
β | The original URL to be shortened |
cloaking |
Bool |
β | If true , hides the destination URL from the user |
password |
String |
β | Password to protect the short link |
redirectType |
Int |
β | Type of redirect (e.g., 301, 302) |
expiresAt |
IntOrString |
β | Expiration timestamp in Unix format |
expiredURL |
String |
β | URL to redirect after expiration |
title |
String |
β | Custom title for the link |
tags |
[String] |
β | Tags to categorize the link |
utmSource |
String |
β | UTM source parameter |
utmMedium |
String |
β | UTM medium parameter |
utmCampaign |
String |
β | UTM campaign parameter |
utmTerm |
String |
β | UTM term parameter |
utmContent |
String |
β | UTM content parameter |
ttl |
IntOrString |
β | Time to live for the short link |
path |
String |
β | Custom path for the short link |
androidURL |
String |
β | Fallback URL for Android |
iphoneURL |
String |
β | Fallback URL for iPhone |
createdAt |
IntOrString |
β | Custom creation timestamp |
clicksLimit |
Int |
β | Maximum number of clicks allowed |
passwordContact |
Bool |
β | Whether contact details are required for password access |
skipQS |
Bool |
β | If true , skips query string on redirect (default: false ) |
archived |
Bool |
β | If true , archives the short link (default: false ) |
splitURL |
String |
β | URL for A/B testing |
splitPercent |
Int |
β | Split percentage for A/B testing |
integrationAdroll |
String |
β | AdRoll integration token |
integrationFB |
String |
β | Facebook Pixel ID |
integrationGA |
String |
β | Google Analytics ID |
integrationGTM |
String |
β | Google Tag Manager container ID |
folderId |
String |
β | ID of the folder where the link should be created |
To ensure your app can handle deep links created via Short.io, you need to configure Universal Links properly using Associated Domains in your Xcode project.
π Note: You must have an active Apple Developer Account to enable Associated Domains. This requires access to your Team ID and Bundle Identifier.
-
Open your Xcode project.
-
Click on your project name in the Project Navigator to open the project settings.
-
Select the "Signing and Capabilities" tab.
-
Choose your Team from the dropdown (linked to your Developer Account).
-
Ensure your Bundle Identifier is correctly set.
-
Click the + Capability button and add Associated Domains.
β Tip: The Associated Domains capability will only appear if you have provided a valid Team and Bundle Identifier.
-
Under Associated Domains, add your Short.io domain in the following format:
applinks:yourshortdomain.short.gy
To enable universal link handling, Short.io must generate the apple-app-site-association
file based on your appβs credentials.
- Go to Short.io.
- Open Domain Settings > Deep links for the short domain you have specified in Xcode.
- In the iOS App Package Name field, enter your team and bundle ID in the following format:
<your_team_id>.<your_bundle_id>
// Example:
ABCDEFGHIJ.com.example.app
- Click the Save button.
This guide explains how to handle Universal Links in iOS applications using the SDK's handleOpen
function. Below are implementation details for both SwiftUI and Storyboard-based projects.
For SwiftUI apps, use the onOpenURL
modifier at the entry point of your app to process incoming URLs and navigate to the appropriate views. Below is an example implementation in SwiftUI.
import SwiftUI
import ShortIOSDK
@main
struct YourApp: App {
let sdk = ShortIOSDK()
var body: some Scene {
WindowGroup {
ContentView()
.onOpenURL { url in
sdk.handleOpen(url) { result in
print("Host: \(result?.host), Path: \(result?.path)")
}
}
}
}
}
For Storyboard apps, implement the scene(_:continue:)
method in your SceneDelegate
to handle Universal Links. Below is an example implementation in Storyboard.
import UIKit
import ShortIOSDK
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
private let sdk = ShortIOSDK()
func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
guard userActivity.activityType == NSUserActivityTypeBrowsingWeb,
let incomingURL = userActivity.webpageURL else {
print("Invalid universal link or URL components")
return
}
sdk.handleOpen(incomingURL) { result in
print("Host: \(result?.host), Path: \(result?.path)")
}
}
}
The handleOpen
function, provided by the SDK, processes a given URL and returns URLComponents
if the URL is valid. It ensures proper parsing of universal links, checking for a valid scheme and returning all available components for further processing.
You can access properties like host
, path
, queryItems
, or other properties from the returned URLComponents
to determine the appropriate navigation or action in your app.