Introduction
Welcome to the documentation for the Giphy iOS SDK! This SDK allows you to easily integrate Giphy’s vast collection of animated GIFs into your iOS applications.
Installation
To integrate the Giphy iOS SDK into your Xcode project, you have three options:
CocoaPods
- Add the following line to your Podfile:
- Run the command
pod install
. - Open the generated
.xcworkspace
file.
pod 'GiphyCoreSDK'
Carthage
- Add the following line to your Cartfile:
- Run the command
carthage update
. - Drag the built frameworks into your Xcode project.
github "Giphy/giphy-ios-sdk-core"
Manual
- Download the Giphy iOS SDK from the GitHub repository.
- Add the frameworks to your Xcode project by navigating to Project Navigator → Your Target → General → Frameworks, Libraries, and Embedded Content. Drag and drop the frameworks into this section.
Usage
Once you have installed the Giphy iOS SDK, you can integrate GIF functionality into your app using the following steps:
Step 1: Import
Import the GiphyCoreSDK module in your Swift file:
// Swift
import GiphyCoreSDK
or import the GiphyCoreSDK module in your Objective-C file:
// Objective-C
@import GiphyCoreSDK;
Step 2: Configure
Before using Giphy SDK features, configure it with your Giphy API key. You can obtain an API key by signing up on the Giphy Developers website.
// Swift or Objective-C
Giphy.configure(apiKey: "YOUR_API_KEY")
Step 3: Search GIFs
To search for GIFs based on a specific query, use the GiphyCore.shared.search
method. Below is a code example to search for GIFs:
// Swift or Objective-C
GiphyCore.shared.search(searchQuery: "your_search_query") { (response, error) in
if let gifs = response?.data {
// Handle the returned gifs
} else if let error = error {
// Handle the error
}
}
Step 4: Display GIFs
You can display the retrieved GIFs using the provided GiphyCollectionView or by customizing your own UI according to your app’s requirements.
/**
Example code to display GIFs using GiphyCollectionView.
*/
let layout = UICollectionViewFlowLayout()
let giphyVC = GiphyViewController(collectionViewLayout: layout)
// Configure the GiphyViewController properties if needed
// giphyVC.delegate = self
// giphyVC.showInModal = true
// Present the GiphyViewController
self.present(giphyVC, animated: true)
Conclusion
Congratulations! You have successfully integrated the Giphy iOS SDK into your project. You are now ready to leverage the power of Giphy’s extensive GIF library and enhance your app’s user experience with animated content.