【发布时间】:2020-10-29 03:36:30
【问题描述】:
我正在学习 SwiftUI。我想编写一个图像浏览器,我可以将其放入“应用程序”目录并将其用作默认图像浏览器。我想在右键菜单中选择我的应用程序:“在应用程序中打开...”
我知道如何在 Windows / Linux 中实现它,我必须确保我的应用程序可以读取作为参数传递的参数。例如:“MyImageBrowser.exe d:\images\photo.jpg”
我知道在里面做什么:
CommandLine.arguments.forEach() { /* do something with the parameters like reading the file */}
或如何显示图像
let url = URL(fileURLWithPath: param) //param is obtained from CommandLine.arguments
let image = NSImage(contentsOf: url)!
和
var body: some View {
Image(nsImage: image)
.frame( maxWidth: .infinity, maxHeight: .infinity, alignment:.center)
}
我不知道的是如何“强制”MacOs 传递带有要打开的图像位置的参数。
我编译了我的代码并将结果 (iSee.app) 复制到 Application 文件夹。
然后我尝试通过单击图像并选择“打开方式...”来打开图像。
我收到警告:
【问题讨论】: