Welcome to the documentation for CSNLineOpener, an open-source library for iOS that provides a convenient way to open URLs in various applications. This documentation will guide you on how to use the library effectively in your iOS projects.
Installation
To install CSNLineOpener in your project, you have multiple options:
Option 1: CocoaPods
If you haven’t already, install CocoaPods by executing the following command in your terminal:
$ gem install cocoapods
Add CSNLineOpener to your Podfile
:
pod 'CSNLineOpener'
Run the pod install
command:
$ pod install
Option 2: Manual
- Download the latest release of CSNLineOpener from the GitHub repository.
- Drag and drop the
CSNLineOpener
folder into your Xcode project. - Ensure “Create groups” is selected and select your target.
- Make sure the library files are added to your target’s “Compile Sources” build phase.
Usage
Importing
Import the CSNLineOpener module wherever you plan to use it:
import CSNLineOpener
Opening URLs
To open a URL using CSNLineOpener, use the following method:
CSNLineOpener.open(urlString: "https://example.com") { (success) in
if success {
// URL opened successfully
} else {
// Failed to open URL
}
}
Replace "https://example.com"
with the desired URL.
Customizing the Excluded Applications List
By default, CSNLineOpener excludes a predefined list of applications from opening URLs. To customize the excluded applications list, use the excludedApps
property:
CSNLineOpener.shared.excludedApps = ["com.example.app"]
In the example above, replace "com.example.app"
with the bundle identifier of the application you wish to exclude.
Getting the List of Available Applications
To retrieve the list of all applications capable of opening a specific URL, use the following method:
CSNLineOpener.getAvailableApps(forURLString: "https://example.com") { (apps) in
print(apps)
}
Replace "https://example.com"
with the target URL.
Examples
Example 1: Opening a URL
The following example demonstrates how to open a URL using CSNLineOpener:
CSNLineOpener.open(urlString: "https://example.com") { (success) in
if success {
print("URL opened successfully")
} else {
print("Failed to open URL")
}
}
Example 2: Customizing the Excluded Applications List
In this example, we customize the list of excluded applications to prevent opening URLs in a specific app:
CSNLineOpener.shared.excludedApps = ["com.example.app"]
Example 3: Getting the List of Available Applications
The following example retrieves the list of available applications capable of opening a specified URL:
CSNLineOpener.getAvailableApps(forURLString: "https://example.com") { (apps) in
print(apps)
}
The retrieved list of applications is printed to the console.