且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Mac OS X上跟踪文件位置?

更新时间:2023-09-30 09:56:04

从10.6开始,它是由书签完成的 NSURL 的功能:

Starting from 10.6, it is done by "Bookmarks" functionality of NSURL:


书签是一种新功能,用于生成对URL标识的资源的持久引用。 。书签是系统从资源URL生成的数据对象。书签数据封装了对基础资源的持久,不透明的引用,以及在创建书签时捕获的资源属性的值。书签可以存储在内存或磁盘中,以后可以用来访问其包含的资源属性值,也可以解析为覆盖基础资源的URL。对于文件系统资源,书签能够查找自创建书签以来已移动或重命名的资源,类似于Alias Manager别名。请注意,在此版本中,书签仅按路径解析。

Bookmarks are a new facility for generating persistent references to resources identified by URLs. A bookmark is a data object generated by the system from a resource URL. The bookmark data encapsulates a durable, opaque reference to the underlying resource as well as value of resource properties captured when the bookmark was created. A bookmark can be stored in memory or on disk and later used to access the resource property values it contains, or resolved to cover the underlying resource’s URL. In the case of file system resources, the bookmark is capable of locating resources that have been moved or renamed since the bookmark was created, similar to Alias Manager aliases. Note that in this release, bookmarks resolve only by path.

NSURL.h中进一步记录了以下新的NSURL方法:

The following new NSURL methods are further documented in NSURL.h:

- (NSData *)bookmarkDataWithOptions:(NSURLBookmarkCreationOptions)options includingResourceValuesForKeys:(NSArray *)keys relativeToURL:( NSURL*)relativeURL error:(NSURL **)error;
- (NSURL*)initByResolvingBookmarkData:(NSData*)bookmarkData options:(NSURLBookmarkResolutionOptions)options relativeToURL:(NSURL *)relativeURL bookmarkDataIsStale:(BOOL *)isStale error:(NSError **)error;
+ (NSURL *)URLByResolvingBookmarkData:(NSData *)bookmarkData options:(NSURLBookmarkResolutionOptions)options relativeToURL:(NSURL *)relativeURL bookmarkDataIsStale:(BOOL *)isStale error:(NSError **)error;
+ (NSDictionary *)resourceValuesForKeys:(NSArray *)keys fromBookmarkData:(NSData *)bookmarkData;


在10.6之前,它是通过 别名

Before 10.6, it was done with aliases.