Reputation: 3677
I am new of macOS Development but i do have experience in iOS Development.
I am developing an installer application for a package XYZ.pkg
And i want to install this package with my own GUI instead of default macOS Installer.
The Package is available in my Application's bundle and when i try to install it via command it crash.
guard let pathOfResource = Bundle.main.path(forResource: "SomePackageName", ofType: ".pkg") else {
return
}
self.loadingView.alphaValue = 1
self.loadingView.layer?.isHidden = false
self.activityIndicator.startAnimation(sender)
let argumentString = "-pkg " + pathOfResource
let argumentString1 = "-target /"
let path = "/usr/sbin/installer "
let arguments = [argumentString,argumentString1]
let task = Process.launchedProcess(launchPath: path, arguments: arguments )
task.waitUntilExit()
self.activityIndicator.stopAnimation(sender)
self.loadingView.alphaValue = 0
Upvotes: 6
Views: 1207
Reputation: 6635
There is a space in the path to the package which the installer command interprets as the end of the package name, and then it finds what looks like nonsense after that. If you enclose the resource path in quotes, that should work:
let argumentString = "-pkg \"\(pathOfResource)\""
Upvotes: 3
Reputation: 25246
Your problem is the space after the path.
let path = "/usr/sbin/installer"
Process throws an exception when it can't find the binary at the given launchPath.
Upvotes: 3