gpt4 book ai didi

objective-c - 了解 Cocoa 中最近使用的文件

转载 作者:搜寻专家 更新时间:2023-10-30 19:56:53 26 4
gpt4 key购买 nike

有没有办法使用 cocoa(或 objective-c)函数列出最近使用的文件?

我想要“最近的文件”之类的东西

感谢您的帮助。

问候,

最佳答案

使用 -[NSDocumentController recentDocumentURLs]。它返回一个 URL 数组,表示您的应用程序最近打开的文档的位置。


根据评论进行编辑:在这种情况下,您需要使用 Launch Services API。例如:

- (NSArray *)globalRecentDocumentsURLs {
LSSharedFileListRef recentDocsFileList;
NSArray *recentDocsFiles;
NSMutableArray *recentDocsURLs = nil;
UInt32 seed;

recentDocsFileList = LSSharedFileListCreate(NULL,
kLSSharedFileListRecentDocumentItems, NULL);
if (! recentDocsFileList) return nil;

recentDocsFiles = (NSArray *)LSSharedFileListCopySnapshot(recentDocsFileList,
&seed);

if (recentDocsFiles) {
recentDocsURLs = [NSMutableArray array];

for (id file in recentDocsFiles) {
CFURLRef fileURL = NULL;
LSSharedFileListItemResolve((LSSharedFileListItemRef)file, 0,
&fileURL, NULL);
if (fileURL) [recentDocsURLs addObject:[(id)fileURL autorelease]];
}

[recentDocsFiles release];
}

CFRelease(recentDocsFileList);

return recentDocsURLs;
}

关于objective-c - 了解 Cocoa 中最近使用的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5945786/

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