デリゲート関数-(BOOL)application:(NSApplication *)theApplication openFile:(NSString *)fileName;
を使用して、アプリケーション自体から以前に保存したファイルをダブルクリックしてアプリケーションを起動しています。
私が抱えている主な問題は、ファイルのパスです。fileName
デスクトップ上の変数内のファイルをダブルクリックすると、次のパスが表示されます。
/Users/Mark/Library/Containers/com.Mark.myApp/Data/Desktop/theFile.ff
私は次のようなものを期待していますが
/Users/Mark/Desktop/theFile.ff
それは私が使用して得るものですNSOpenPanel
そのパスをどのように管理できますか?
編集 - - -
を使用してファイルのコンテンツをアーカイブ解除しようとすると
[NSKeyedUnarchiver unarchiveObjectWithData:[NSData dataWithContentsOfURL: filename]];
エラーが発生します-[NSKeyedUnarchiver initForReadingWithData:]: data is NULL
しかし、NSOpenPanelを使用して同じファイルを読み取ると、正しく機能します。
ソースの追加を編集-----------
これは基本的に、ファイルをダブルクリックしてアプリケーションの起動を管理するために使用するコードです。
-(BOOL)application:(NSApplication *)theApplication openFile:(NSString *)fileName{
self.openFile = [NSURL URLWithString:fileName];
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
if (self.openedFile != nil) {
id obj = [NSKeyedUnarchiver unarchiveObjectWithData:[NSData dataWithContentsOfURL:filename]];
- do something with the obj -
}
}