I’m using the delegate function -(BOOL)application:(NSApplication *)theApplication openFile:(NSString *)fileName; to launch my application by double click over a file previously saved from the application itself.
The main problem I have is the path of the file. If I double click a file on my desktop in the fileName variable I get this path:
/Users/Mark/Library/Containers/com.Mark.myApp/Data/Desktop/theFile.ff
While I’m expecting something like
/Users/Mark/Desktop/theFile.ff
That is what I get using the NSOpenPanel
How can I manage that path?
Edit——
When I try to unarchive the content of the file using
[NSKeyedUnarchiver unarchiveObjectWithData:[NSData dataWithContentsOfURL: filename]];
I get the error -[NSKeyedUnarchiver initForReadingWithData:]: data is NULL
but when I read the same file using NSOpenPanel it works correctly.
Edit Adding Source ———–
This is essentially the code that I use to manage the launch of the application by double click on a file.
-(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 -
}
}
whats the problem? they both point to the same file. The first is just the sandbox representation (a symlink is used so the app has access to the desktop without breaking the sandbox)
EDIT: in your code you use URLWithString when In fact you should use fileURLWithPath.
The String isn’t an URL but a POSIX path that has be transformed into an URL using fileURLWithPath