ProductPromotion
Logo

Swift

made by https://0x3d.site

GitHub - MaksimKurpa/Linker: 🎯 Your easiest way to handle all URLs.
🎯 Your easiest way to handle all URLs. Contribute to MaksimKurpa/Linker development by creating an account on GitHub.
Visit Site

GitHub - MaksimKurpa/Linker: 🎯 Your easiest way to handle all URLs.

GitHub - MaksimKurpa/Linker: 🎯 Your easiest way to handle all URLs.


Installation

Dependency Managers

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate Linker into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

pod 'Linker'

Then, run the following command:

$ pod install

Carthage is a decentralized dependency manager that automates the process of adding frameworks to your Cocoa application.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate Linker into your Xcode project using Carthage, specify it in your Cartfile:

github "Linker"

Usage

(see sample Xcode project Demo)

The main thought of this framework is useful and convenient handling of external and internal URLs in your iOS application. Linker provides only one function to install your own handler to specific URL. A dependency between specific URL and your closure is based on scheme and host of each URL. That is you can configure miscellaneous behavior for different components of specific URL. You can split handling by query with different parameters and/or by path, fragment.

Swizzled functions:

UIApplication.shared - openURL:options:completionHandler:

UIApplication.shared - openURL: (deprecated since iOS 10.0)

UIApplication.shared.delegate - application:openURL:options:

UIApplication.shared.delegate - application:openURL:sourceApplication:annotation: (deprecated since iOS 9.0)

UIApplication.shared.delegate - application:handleOpenURL: (deprecated since iOS 9.0)

For complience with URL style, use format:

your_app_url_scheme://inapp_am/buy_subscription?type=subscription&productID=com.yourapp.7days_trial#test

where:

scheme - your_app_url_scheme,

host - inapp_am,

path - buy_subscription

query - type=subscription&productID=com.yourapp.7days_trial

fragment - test

If you don't need configuration with complexed behavior, you can use URL just with host:

your_app_url_scheme://some_host_from_your_app

One special case - handle external URLs when app isn't launched. You should install closure for specific URL and if this url will be in pair with UIApplicationLaunchOptionsKey in launchOptions - this url will be handled.

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool 
{
    let launchURL = URL(string: "linker://launchURL")!
    
    //if launchUrl equal launchOptions?[UIApplicationLaunchOptionsKey.url] -> this closure will be handled after app launch
    Linker.handle(launchURL, closure: { url in
	print("Your URL has been handle!")
    })
        return true
    }

In other cases of usage you should set your handle closure for special URL before calling its from somewhere. If you have a few places where you need handle one specific url, you should reassign closure where latest set closure should have right context.

class ViewController: UIViewController {
    
    let sourceURL = URL(string: "linker://viewcontroller?title=ExampleAlert&description=ExampleDescriptionAlert")!

    @IBAction func action(_ sender: Any) {
        UIApplication.shared.open(sourceURL, options: [:], completionHandler: nil)
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        Linker.handle(sourceURL) { url in
        
            guard let queryItems = URLComponents(url: url, resolvingAgainstBaseURL: true)?.queryItems! else {
                return }
            var title : String? = nil
            var description: String? = nil
            
            for item in queryItems {
                if item.name == "title" {
                    title = item.value
                }
                if item.name == "description" {
                    description = item.value;
                }
            }
            
            if let name = title, let message = description {
                let alertVC = UIAlertController(title: name, message: message, preferredStyle: UIAlertControllerStyle.alert)
                alertVC.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel, handler: {action in
                    alertVC.dismiss(animated: true, completion: nil)
                }))
                self.present(alertVC, animated: false, completion: nil)
            }
        }
    }
}

You can also find Objective-C version of this here.

Contributing

Issues and pull requests are welcome!

Author

Maksim Kurpa - @maksim_kurpa

License

This code is distributed under the terms and conditions of the MIT license.

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory