本文介绍了如何在Mac OS X上跟踪文件位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的一项不错的功能是无论如何跟踪文件发生在那些文件上。我正在处理的应用程序需要跟踪用户拥有的多个文件的位置。用户可以移动或删除这些文件,并且即使发生位置更改时我的应用程序未运行,我的应用程序也需要知道这些文件在哪里。

One of the nice features of BBEdit is how it keeps track of files no matter what happens to those files. The application that I am working on needs to keep track of the location of a number of files owned by the user. The user can move or delete these files and my application needs to know where those files are even if my application was not running at the time the change in location happened.

什么是针对此问题的推荐策略,或者可能是什么?

What is a recommended strategy for this problem or what could it be?

在应用程序运行时跟踪文件不是问题。无论应用程序未运行时那些文件发生了什么情况,我都希望它们在运行时具有正确的文件路径。

Keeping track of files while the application is running is not the problem. I want the correct path to the files when my application is running no matter what happened to those files when my application was not running.

手动搜索最佳文件

推荐答案

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

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

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.

这篇关于如何在Mac OS X上跟踪文件位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 16:04