swift - 如何简化可可应用程序的安全运行时流程
问题描述
我是 swift 的新手,一般来说是苹果环境的新手,长时间的 windows 用户。我目前的问题是我希望我的应用程序可以在任何 MacOS 中运行,没有任何密码问题,目前在 Xcode 中启动时它会询问我密码,然后按预期工作。(仅适用于 sudo -S,否则不会)
为了达到这一点,我不得不禁用沙盒,不确定这是否是我应该做的,但当时这是我能让应用程序工作的唯一方法。
同样在一些帖子中,我看到在 Mojave 中,建议在此类应用程序中为终端设置全盘访问,所以我这样做了。
另一个问题是如何调整这个应用程序,以便我可以把它交给朋友,他可以在没有任何密码和其他开发人员技巧的情况下使用它。
谢谢。
import Cocoa
class ViewController: NSViewController {
@IBOutlet weak var txtUrl1: NSTextField!
@IBOutlet weak var btnDownload: NSButton!
@IBAction func clickDownload(_ sender: Any) {
let url = txtUrl1.stringValue
let command = "sudo -S /usr/local/bin/youtube-dl -f best " + url + " -o '/Users/Matthew/Library/Containers/matthew.youtube/Data/%(title)s.%(ext)s' "
shell(command)
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
func shell(_ command: String) -> String {
let task = Process()
task.launchPath = "/bin/bash"
task.arguments = ["-c", command]
let pipe = Pipe()
task.standardOutput = pipe
task.launch()
let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output: String = NSString(data: data, encoding: String.Encoding.utf8.rawValue)! as String
return output
}
override var representedObject: Any? {
didSet {
// Update the view, if already loaded.
}
}
}
解决方案
推荐阅读
- c# - 如何在 .net 核心中注册继承的通用存储库
- c# - c# Roll Dice 模拟返回每边落地的次数
- python - 为什么在打印列表时没有出现错误时出现 IndexError: string index out of range?
- typescript - Typescript 在 ES11 语法上崩溃
- html - 来自 Wikipedia 的解析器用户页面信息。如何去除冗余信息?
- html - 如何在 HTML 中使用模式允许几个不同的符号
- excel - 在 Excel 自定义函数中使用 Excel 上下文
- reactjs - react js中的url参数中显示的登录凭据
- java - 使用多个线程划分数组元素并以块的形式并行处理
- sql-server - 如何只显示一个 MIN 日期?