简体   繁体   English

如何在macOS Apps中安装软件包

[英]How to install package in macOS Apps

I am new of macOS Development but i do have experience in iOS Development. 我是macOS Development的新手,但我确实有iOS开发经验。 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. 我正在为一个包XYZ.pkg开发一个安装程序应用程序我想用我自己的GUI而不是默认的macOS安装程序来安装这个包。 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

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. 当在给定的launchPath中找不到二进制文件时,进程抛出异常。

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)\""

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM