在 iPhone 沙箱中查找文件

发布于 2024-11-01 19:27:04 字数 216 浏览 3 评论 0原文

在我的应用程序开始时,用户录制他们的声音,然后将其保存为沙箱中的“recorded.wav”。稍后如何创建一个指示其位置的字符串?我想要类似这样的内容:

/var/folders/u6/u6pKbm2MFriwajkdt-OQME+++TI/-Tmp-/recorded.wav

谢谢,

请记住这是针对 iPhone 设备和模拟器的。

At the beginning of my app the user records their voice which is then saved as 'recorded.wav' in the sandbox. How do I later create a string indicating it's location? I would like something that looks like:

/var/folders/u6/u6pKbm2MFriwajkdt-OQME+++TI/-Tmp-/recorded.wav

Thanks,

Keep in mind this is for the iPhone device and simulator.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

晒暮凉 2024-11-08 19:27:04

NSHomeDirectory() 返回应用程序沙箱的路径。然后您可以访问其中的任何文件或目录。

NSString *home = NSHomeDirectory();
NSString *documentsPath = [home stringByAppendingPathComponent:@"Documents"];

还有 NSTemporaryDirectory() 它返回特定于您的应用程序的临时文件夹的路径。请注意,在模拟器中运行应用程序时,NSTemporaryDirectory() 将返回系统范围的目录。


如果您喜欢更通用的解决方案,请查找有关 NSSearchPathForDirectoriesInDomains() 函数的文档。

NSHomeDirectory() returns the path to your application's sandbox. You can then reach any file or directory within it.

NSString *home = NSHomeDirectory();
NSString *documentsPath = [home stringByAppendingPathComponent:@"Documents"];

There is also NSTemporaryDirectory() which returns the path to the temp folder specific to your app. Do note, that when running your app in the Simulator, NSTemporaryDirectory() will return a system-wide directory.


If you like a more general solution, lookup the documentation on NSSearchPathForDirectoriesInDomains() function.

梦里寻她 2024-11-08 19:27:04

您可以通过 NSSearchPathForDirectoriesInDomains 获取文件的路径 基础函数如下:

// Get our document path.
NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentPath = [searchPaths objectAtIndex:0];

// Get the full path to our file.
NSString *samplePath = [documentPath stringByAppendingPathComponent:@"recorded.wav"];

You can get the path to your file via the NSSearchPathForDirectoriesInDomains foundation function as such:

// Get our document path.
NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentPath = [searchPaths objectAtIndex:0];

// Get the full path to our file.
NSString *samplePath = [documentPath stringByAppendingPathComponent:@"recorded.wav"];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文