Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocoa Mac应用程序沙盒-NSHomeDirectory()问题_Cocoa_Sandbox - Fatal编程技术网

Cocoa Mac应用程序沙盒-NSHomeDirectory()问题

Cocoa Mac应用程序沙盒-NSHomeDirectory()问题,cocoa,sandbox,Cocoa,Sandbox,我刚刚沙盒了我的Mac应用程序,在我的应用程序中,我将图像保存在documents文件夹中。我有这个文件URL:file:///Users/myUser/Documents/myApp/Images/logo.jpg 在我的沙盒之后,我使用NSHomeDirectory()而不是直接转到Documents文件夹。这样做的问题是,它去掉了文件://。基本上,如何将文件://附加到URL 这是NSHomeDirectory()给我的信息: /Users/myUser/Library/Containe

我刚刚沙盒了我的Mac应用程序,在我的应用程序中,我将图像保存在documents文件夹中。我有这个文件URL:
file:///Users/myUser/Documents/myApp/Images/logo.jpg

在我的沙盒之后,我使用NSHomeDirectory()而不是直接转到Documents文件夹。这样做的问题是,它去掉了
文件://
。基本上,如何将
文件://
附加到URL

这是
NSHomeDirectory()
给我的信息:

/Users/myUser/Library/Containers/com.company.myApp/Data/myApp/Images/logo.jpg
稍后,用户可以选择另一个目录,然后我可以使用电源盒,但在用户选择之前,我需要能够将文件读/写到主目录

有什么想法吗?

NSHomeDirectory()
返回一个
NSString
,而不是
NSURL
。您可以通过调用以下命令将其转换为
NSURL

NSURL* url = [NSURL fileURLWithPath:NSHomeDirectory()];


当然,您也可能希望使用而不是
NSHomeDirectory()

。我想我做这件事时太累了。谢谢