IMG_5219 IMG_5220

Main Features

  • Dark & Light mode support
  • Synced with Product Hunt API
  • Cached in UserDefaults
  • Refreshed when app becomes active

References

Here are some iOS and macOS apps using Product Hunt Badge, give it a try!

Add your app

Documentation

Authentication

In order to refresh upvotes count, you need to provide authentication information so the badge can communicate with Product Hunt API.

You can generate tokens by signing in to Product Hunt, then going to API Dashboard.

Application or Developer Token? Here is what Product Hunt API Documentation mentions:

But… i just wanted to run a simple script?

  • The oauth2 flow is a bit of a overkill if you just want to run a few scripts
  • We provide a developer_token (does not expire, linked to your account) in the API dashboard

Developer Token

@main
struct SideProjectApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
                .productHuntCredentials(.developerToken("{TOKEN}"))
        }
    }
}

Application Credentials

@main
struct SideProjectApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
                .productHuntCredentials(.application(
                    clientId: "API_KEY",
                    clientSecret: "API_SECRET"
                ))
        }
    }
}

Tip

Inject your Product Hunt credentials at your root view so it can be accessible wherever you embed the badge in your app.

Usage

You can either identify your Product Hunt post by its slug or id:

// Product Hunt Badge using its slug (String)
ProductHuntBadge(slug: "stepup")
// Product Hunt Badge using its id (Int)
ProductHuntBadge(id: 471947)

Also, keep in mind you can override system appearance using colorScheme environment value:

ProductHuntBadge(slug: "stepup")
    .environment(\.colorScheme, .dark)