
[英]Swift , Xcode, iOS - How to handle a file sent with 'Open in…' from another app to my own app
[英]How to access path sent by `open` command to Swift GUI app
open
命令可用於將文件發送到程序,如下例所示:
open -a "Google Chrome" Untitled.png
Swift GUI 應用程序將使用什么來接收通過該命令發送的路徑?
我已經在我的主視圖的init()
function 中嘗試過這個
if CommandLine.arguments.count != 1 {
path = CommandLine.arguments[1]
}
但路徑似乎沒有發送到那里。
在macOS 上的 Swift 中:使用 URL 作為參數打開 Chrome,問題是詢問如何打開Chrome並從他們的應用程序中傳遞一個 URL。 我正在嘗試打開我的應用程序並通過從終端調用的open
命令傳遞文件。
您找不到 arguments 的原因是您沒有在命令中將任何 arguments 傳遞給應用程序。
與MyApp myFileURL
不同, open -a MyApp myFileURL
實際上並沒有將myFileURL
傳遞給MyApp
。
要將任何 arguments 實際傳遞給MyApp
,您需要專門使用--args
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.