Welcome to the documentation for FSOpenInInstagram!
FSOpenInInstagram is a simple and lightweight library that allows you to open Instagram directly from your iOS app. It provides an easy way to share images and videos to Instagram using the Instagram app installed on the user’s device.
Installation
To install FSOpenInInstagram, you can use CocoaPods:
pod 'FSOpenInInstagram'
Alternatively, you can manually integrate FSOpenInInstagram into your project by downloading the source files and adding them to your project.
Usage
Note: Before using FSOpenInInstagram, make sure you have the Instagram app installed on your device.
Opening Instagram
To open Instagram and share a media file, you can use the following code:
import FSOpenInInstagram
if FSOpenInInstagram.canOpenInstagram() {
// Specify the path to your media file (image or video)
let mediaPath = "path/to/your/media/file"
FSOpenInInstagram.open(mediaPath: mediaPath)
} else {
print("Instagram app is not installed on the device.")
}
Handling Success and Failure
If the sharing to Instagram is successful, the app will be launched and the user can proceed with posting the media file. However, if the sharing fails (for example, if the Instagram app is not installed), you can handle the error by implementing the following delegate method:
import FSOpenInInstagram
// Implement FSOpenInInstagramDelegate
class MyViewController: UIViewController, FSOpenInInstagramDelegate {
override func viewDidLoad() {
super.viewDidLoad()
FSOpenInInstagram.shared.delegate = self
}
// Handle sharing failure
func openInInstagramFailed() {
print("Failed to open Instagram app.")
}
// Handle sharing success
func openInInstagramSucceeded() {
print("Successfully opened Instagram app.")
}
}
Make sure to set the delegate before calling the open
method to receive the failure or success callbacks.
Customizing the Media Caption
You can add an optional caption to the media file being shared. To do this, modify the code snippet from the previous section:
import FSOpenInInstagram
// Specify the path to your media file (image or video)
let mediaPath = "path/to/your/media/file"
// Create a caption
let caption = "Check out this awesome image!"
FSOpenInInstagram.open(mediaPath: mediaPath, caption: caption)
The caption will be pre-filled in the Instagram post screen.
Requirements
- iOS 11.0+
- Swift 4.x – 5.x
- Xcode 10+
License
FSOpenInInstagram is available under the MIT license. See the LICENSE file for more info.
Contributing
If you have any suggestions, bug reports, or contributions, please submit them to the GitHub repository.