RedirectButton(
    keyword: "iPhone 16 pro", 
    redirection: .amazonShopping
) {
    Text("TAKE MY MONEY!")
}ShopIt simplifies redirection to various online shopping platforms or search engines like Amazon, Google etc.
- Easy redirection to popular shopping sites like Amazon, eBay, Walmart, and more. See the complete list at Supported Platforms.
- SwiftUI compatible for quick integration into your apps.
- Customizable buttons for flexible and straightforward redirection.
- Demo app & usage example can be found in here
Follow these steps to install ShopIt using SPM:
- From within Xcode 13 or later, choose File>Swift Packages>Add Package Dependency.
- At the next screen, enter the URL for the ShopIt repository in the search bar then click Next.
https://github.com/enebin/ShopIt.git
- For the Version rule, selectUp to Next Minorand specify the current ShopIt version then clickNext.
- On the final screen, select the ShopItlibrary and then clickFinish.
ShopIt should now be integrated into your project 🚀
You can simply use the RedirectButton to add a redirection to your app:
RedirectButton(keyword: "iPhone 16 pro", redirection: .amazonShopping) {
    Text("Buy on Amazon")
}Done! 🪄
If you need to handle much complicated behavior, then shopitRedirector will be the perfert solution.
Here's how to use it:
- Register the openURLto redirector using@Environment(\.shopitRedirector)
import SwiftUI
struct ContentView: View {
    @Environment(\.openURL) private var openURL
    @Environment(\.shopitRedirector) private var redirector
    
    var body: some View {
        SomeView()
            .onAppear {
                redirector.register(openURL)
            }
    }
}Caution
YOU MUST register the openURL to redirector before using it, or you can get error.
Note
RedirectButton automatically handles registration of openURL.
- Perform a redirection
Button("Buy on Amazon") {
    Task {
        let favorite = await viewModel.getFavoriteProduct()
        try await redirector.redirect(keyword: favorite, to: .amazonShopping)
    }
}Don't worry if the platform you're looking for isn't available. ShopIt supports creating your own redirections.
You can define custom redirections by conforming to the Redirectable protocol. Here's a quick example:
struct ExampleShopRedirection: Redirectable {
    public let schemeUrl: QueryableURL
    public let webUrl: QueryableURL
    
    init() {
        self.schemeUrl = QueryableURL(
            baseURL: URL(string: "exampleshop://search")!
        ) { keyword in
            [URLQueryItem(name: "query", value: keyword)]
        }
        
        self.webUrl = QueryableURL(
            baseURL: URL(string: "https://www.exampleshop.com/search")!
        ) { keyword in
            [URLQueryItem(name: "query", value: keyword)]
        }
    }
}
// In a view...
RedirectButton(keyword: "iPhone 16 pro", redirection: ExampleShopRedirection()) {
    Text("Buy This!")
}
// or 
Button("Buy This!") {
    Task {
        try await redirector.redirect(keyword: "iPhone 16 pro", to: ExampleShopRedirection())
    }
}Note
If you want to add your own redirection to this package, feel free to submit a PR. Your contributions are always welcome!
You can explore the complete usage flow in our demo app.
| Name | App | Web | 
|---|---|---|
| ✅ | ✅ | |
| Amazon | ✅ | ✅ | 
| eBay | ✅ | ✅ | 
| Walmart | ✅ | ✅ | 
| BestBuy | ✅ | ✅ | 
| Coupang | ✅ | ✅ | 
| MarketKurly | ✅ | ✅ | 
| Naver Store | ✅ | ✅ | 
Contributions are welcome! You can contribute to the project through bug reports, feature suggestions, and pull requests.
This project is licensed under the MIT License. See the LICENSE file for more details.
