Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install package in macOS Apps

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
like image 636
Syed Qamar Abbas Avatar asked Feb 15 '17 17:02

Syed Qamar Abbas


2 Answers

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.

like image 123
catlan Avatar answered Nov 02 '22 15:11

catlan


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)\""
like image 32
Dave Weston Avatar answered Nov 02 '22 16:11

Dave Weston