BitlyKit is a versatile Swift library that provides developers with a simple and efficient way to integrate Bitly’s powerful link management capabilities into their iOS apps. With BitlyKit, you can generate short links, track click metrics, and manage your Bitly links seamlessly.
Features
- Shorten long URLs to compact and shareable links
- Customize and personalize your short links
- Track click metrics and analyze link performance
- Retrieve historical click and engagement data
- Create, edit, and manage Bitly links programmatically
- Support for both authenticated and public API access
Getting Started
Installation
To get started with BitlyKit, follow these steps:
- Open your terminal and navigate to your project directory.
- Add BitlyKit to your project by running the command:
pod 'BitlyKit'
. - Run
pod install
to install the BitlyKit dependencies. - Import BitlyKit into your project:
import BitlyKit
.
Authentication
In order to use BitlyKit, you will need a valid Bitly access token. You can obtain one by following these steps:
- Sign in to your Bitly account or create a new one.
- Navigate to the Bitly Developer Dashboard.
- Create a new generic access token for your app.
- Copy the generated access token and securely store it in your app.
Usage
BitlyKit provides a comprehensive set of methods and functionalities to integrate Bitly link management seamlessly into your app. Here are some common use cases:
Shorten URLs
To generate short links using BitlyKit, utilize the Bitly.shorten
method:
Bitly.shorten(longURL: "https://example.com") { result in
switch result {
case .success(let link):
print("Short link: \(link.shortURL)")
case .failure(let error):
print("Error: \(error.localizedDescription)")
}
}
Customize Links
You can customize and personalize your short links using BitlyKit’s Bitly.customizeLink
method. Here’s an example:
Bitly.customizeLink(link: "http://bit.ly/abc123",
title: "My Custom Link",
tags: ["app", "swift"]) { result in
switch result {
case .success(let link):
print("Customized link: \(link.shortURL)")
case .failure(let error):
print("Error: \(error.localizedDescription)")
}
}
Track Click Metrics
Use BitlyKit’s Bitly.linkMetrics
method to retrieve click metrics and analyze the performance of your links:
Bitly.linkMetrics(link: "http://bit.ly/abc123") { result in
switch result {
case .success(let metrics):
print("Clicks: \(metrics.clicks)")
print("Engagement: \(metrics.engagement)")
case .failure(let error):
print("Error: \(error.localizedDescription)")
}
}
Manage Bitly Links
With BitlyKit, you can programmatically create, edit, and manage Bitly links effortlessly. Here’s an example:
Bitly.createLink(title: "My App Link",
longURL: "https://example.com",
tags: ["app", "ios"]) { result in
switch result {
case .success(let link):
print("Created link: \(link.shortURL)")
case .failure(let error):
print("Error: \(error.localizedDescription)")
}
}
API Access
BitlyKit supports both authenticated and public API access. For authenticated requests, ensure you set your access token before making any API calls:
Bitly.accessToken = "YOUR_ACCESS_TOKEN"
Summary
BitlyKit provides developers with a flexible and powerful library to integrate Bitly link management capabilities seamlessly into their iOS apps. With BitlyKit, you can generate short links, track click metrics, and manage your Bitly links programmatically. Start simplifying your link management workflow today with BitlyKit!