takecian / SwiftRater

A utility that reminds your iPhone app's users to review the app written in pure Swift.
MIT License
356 stars 42 forks source link

SwiftUI Support #39

Closed JulesMoorhouse closed 1 year ago

JulesMoorhouse commented 2 years ago

Hey,

I've used SwiftRater in other older apps in the past, Objective C apps, I've found it works really well.

I'd really like to use this with SwiftUI now.

Jules.

markgravity commented 2 years ago

@JulesMoorhouse you can easily do it in SwiftUI with something like this

@main
struct SwiftRateDemoApp: App {
    @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate

    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

class AppDelegate: NSObject, UIApplicationDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
SwiftRater.daysUntilPrompt = 7
        SwiftRater.usesUntilPrompt = 10
        SwiftRater.significantUsesUntilPrompt = 3
        SwiftRater.daysBeforeReminding = 1
        SwiftRater.showLaterButton = true
        SwiftRater.debugMode = true
        SwiftRater.appLaunched()
        return true
    }
}

More info about UIApplicationDelegateAdaptor here

takecian commented 1 year ago

Thanks markgravity for the follow up. I've added this in README. https://github.com/takecian/SwiftRater/commit/3cf8ff522902f4d8f0aa5cfecdd842e517d5ed91