gpt4 book ai didi

swift - Finder "open with"应用 list

转载 作者:行者123 更新时间:2023-11-30 11:40:16 24 4
gpt4 key购买 nike

所以我让它工作了,然后我调整了一些内容:文档 Controller - 子类化为

class DocumentController : NSDocumentController {
override func typeForContents(of url: URL) throws -> String {
return "Document"
}
}

以及用于解析 .webloc 文件的 URL 帮助程序:

extension URL {
var webloc : URL? {
get {
do {
let data = try Data.init(contentsOf: self) as Data
let dict = try! PropertyListSerialization.propertyList(from:data, options: [], format: nil) as! [String:Any]
let urlString = dict["URL"] as! String
return URL.init(string: urlString)
}
catch
{
return nil
}
}
}

}

当我在分类打开与制作文件文档问题时丢失了测试应用程序的 Finder 菜单“打开方式”条目时 - 请参阅下文。我确实有一个应用程序委托(delegate) openFile: as

func application(_ sender: NSApplication, openFile: String) -> Bool {
let urlString = (openFile.hasPrefix("file://") ? openFile : "file://" + openFile)
let fileURL = URL(string: urlString.addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlQueryAllowed)!)!
return self.doOpenFile(fileURL: fileURL)
}
func doOpenFile(fileURL: URL) -> Bool {
let dc = NSDocumentController.shared()
var status : Bool = false
var itemURL = fileURL

// Resolve alias, container webloc bookmark before target bookmarking
if let original = (itemURL as NSURL).resolvedFinderAlias() { itemURL = original }
if itemURL.absoluteString.hasSuffix("webloc") {
if isSandboxed() != storeBookmark(url: itemURL as URL) {
Swift.print("Yoink, unable to bookmark (\(itemURL))")
}
if let webURL = itemURL.webloc {
itemURL = webURL
}
}
else
{
if isSandboxed() != storeBookmark(url: itemURL as URL) {
Swift.print("Yoink, unable to bookmark (\(itemURL))")
return false
}
}

dc.openDocument(withContentsOf: itemURL, display: true, completionHandler: { (nextURL, wasOpen, error) in
if error != nil {
NSApp.presentError(error!)
Swift.print("Yoink, unable to open doc for (\(String(describing: nextURL)))")
status = false
}
else
{
let newWindow = nextURL?.windowControllers.first?.window
(newWindow?.contentView?.subviews.first as! MyWebView).next(url: itemURL)
newWindow?.offsetFromKeyWindow()
status = true
}
})
return status
}

当我尝试打开“webloc”网址而不是为其创建文档时,我的 View Controller 收到错误 (presentError:) - 微妙的区别?

无论如何,现在我的菜单条目在 Finder 中消失了,所以我正在寻找一个 list 来验证我[仍然]设置正确,我的应用程序的单个文档 Info.plist 显示为(相关的文档) :

enter image description here

我什么时候失踪了!?这项工作使用了其他人的回复:解决Finder alias 、沙箱支持和 webloc 内容解析。

我试图解决一个问题,即当我进行“某些”更改并丢失 Finder 的“打开方式”条目时,我的 -URL.webloc() 函数无法解决搜索字符串编码的文件名 - webloc。应用程序。

因此,为了我和其他人的利益,我们需要一个检查 list (食谱)来运行。这个应用程序是一个测试迷你浏览器,使用 WKWebView 和 next(url:) 函数来加载下一个 url。

最佳答案

Info.plist 损坏 - 检查您的 Info.plist 作为源代码,如下所示

enter image description here

这些启动服务 token ,即 LSItemContentTypes 对我来说是新的,虽然我没有意识到我何时完成了此操作,但我立即知道这不是我过去做过的事情。

郑重声明,让您的应用“注册”是一种隐式行为,如 Launch Services 中所定义。 。如其中所述,除了正确设置 Info.plist 之外,您不需要执行任何明确的操作。

我的问题是将几种不同的文件类型扩展名注册为单独的文档类型 - 非初学者,相反,我所需要的只是将所有可查看类型集中在单个文档类型下,而这种“胖手指”可能发生在疯狂的情况下急于纠正看起来不好的事情。无论如何,您的需求可能会有所不同:多种文档类型。

关于swift - Finder "open with"应用 list ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49354041/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com