ShortIOApp is a sample iOS project that demonstrates how to integrate and use the ShortIOSDK for generating short links and handling universal deep links using Short.io.
This project helps developers understand how to:
- Set up and use
ShortIOSDK
- Generate short URLs with customizable parameters
- Integrate and handle Universal Links in SwiftUI and UIKit
- iOS 13.0+
- Xcode 13.0+
- Swift 5+
- A valid Short.io account
git clone https://github.com/Short-io/ios-sdk-example.git
# For SwiftUI project
cd ios-sdk-example/SwiftUIProject
# For Storyboard (UIKit) project
cd ios-sdk-example/StoryboardProject
Open ShortIOApp.xcodeproj
or ShortIOApp.xcworkspace
in Xcode, depending on the structure.
Open the appropriate file:
- SwiftUI:
ContentView.swift
- UIKit:
ViewController.swift
Replace the placeholder with your Short.io Public API Key:
let apiKey = "your_api_key"
🔗 Need help finding your API key?
Follow this guide in the ShortIOSDK README.
In the same file (ContentView.swift
or ViewController.swift
), provide your Short.io domain and the original URL you want to shorten:
let parameters = ShortIOParameters(
domain: "your_domain", // e.g., example.short.gy
originalURL: "https://{your_domain}" // The destination URL
)
The app demonstrates:
Using your domain and original URL, you can generate a short link like this:
let sdk = ShortIOSDK()
let parameters = ShortIOParameters(
domain: "your_domain",
originalURL: "https://yourdomain.com"
)
let apiKey = "your_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 error):
print("Error: \(error.message)")
}
} catch {
print("Unexpected error: \(error)")
}
}
Use the .onOpenURL
modifier to process incoming links:
.onOpenURL { url in
sdk.handleOpen(url) { result in
print("Navigated to path: \(result?.path ?? "")")
}
}
Handle incoming links by implementing the scene(_:continue:)
method in the SceneDelegate
file:
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)")
}
}
If you'd like to contribute to the SDK or sample app, please fork the repository and submit a pull request.