Skip to content

Instantly share code, notes, and snippets.

@steipete
Last active May 5, 2021 15:18
Show Gist options
  • Save steipete/450e1f2ec439df0a3a4b3578b46f4e42 to your computer and use it in GitHub Desktop.
Save steipete/450e1f2ec439df0a3a4b3578b46f4e42 to your computer and use it in GitHub Desktop.
Sparkle + SwiftUI
lass AppUpdateHandler: ObservableObject {
#if SPARKLE
private let delegateHandler = SparkleDelegateHandler()
let sparkle: SPUStandardUpdaterController
init() {
// Setup sparkle updater
// https://docs.microsoft.com/en-us/appcenter/distribution/sparkleupdates
// https://rambo.codes/posts/2021-01-08-distributing-mac-apps-outside-the-app-store
sparkle = SPUStandardUpdaterController(updaterDelegate: delegateHandler, userDriverDelegate: delegateHandler)
}
func checkForUpdates() {
// https://sparkle-project.org/documentation/
sparkle.checkForUpdates(delegateHandler)
}
private class SparkleDelegateHandler: NSObject, SPUUpdaterDelegate, SPUStandardUserDriverDelegate {
func feedURLString(for updater: SPUUpdater) -> String? {
"https://api.appcenter.ms/..." // or whatever you use
}
}
#endif
}
@steipete
Copy link
Author

steipete commented Apr 22, 2021

@StateObject var updateHandler = AppUpdateHandler()

in your main app

@imWildCat
Copy link

typo: *class

Question: Do we need to build a macOS plugin for Sparkle like this example?

@steipete
Copy link
Author

steipete commented May 5, 2021

Yes, you need to follow the 2.0 integration guide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment