NSSearchPathForDirectoriesInDomains 麻烦(掉头发快)

发布于 2024-07-29 08:59:10 字数 1156 浏览 3 评论 0原文

我很快就秃顶了,需要帮助!

我正在编写一个需要访问目录的应用程序。 我希望得到一种形式的路径 /Users/me/Library/Application Support/iPhone Simulator/User/Applications/6958D21C-C94B-4843-9EF1-70406D0CA3A3/Documents

然而,我的应用程序给了我 /Users/me/Library/Application Support/iPhone Simulator/User/Documents 这不是我想要的,因为没有写访问权限。

这是我的代码的彻底精简版本。 请注意,您需要查看模拟器中的控制台才能看到输出。 我检查了我所知道的所有参考资料,但没有成功改变这种行为。 它是一些编译器选项吗? 或者我必须在 Info.plist 中更改一些内容? 请大家...

更新:由于一些非常奇怪的原因,我的应用程序没有被沙箱化。 为什么?

文件 DirTestAppDelegate.h

#import <UIKit/UIKit.h>

@interface DirTestAppDelegate : NSObject <UIApplicationDelegate> 
{
    UIWindow *window;
}

@end

文件 DirTestAppDelegate.m

#import "DirTestAppDelegate.h"

@implementation DirTestAppDelegate
- (void)applicationDidFinishLaunching:(UIApplication *)application 
{    
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSLog(documentsDirectory);
}


- (void)dealloc 
{
        [super dealloc];
}
@end

I am getting bald quite quick and need help!

I am writing an app which needs to access directories. I was hoping to get a path of the form
/Users/me/Library/Application Support/iPhone Simulator/User/Applications/6958D21C-C94B-4843-9EF1-70406D0CA3A3/Documents.

However my app is giving me /Users/me/Library/Application Support/iPhone Simulator/User/Documents which is not what I want because have no write access.

Here is a thoroughly stripped down edition of my code. Note that you need to look at the console in the simulator to see the output. I have checked all the references I know and have no success to change the behaviour. Is it some compiler option? Or something I have to change in Info.plist? Anybody please...

Update: For some very strange reason my app is not being sandboxed. Why?

File DirTestAppDelegate.h

#import <UIKit/UIKit.h>

@interface DirTestAppDelegate : NSObject <UIApplicationDelegate> 
{
    UIWindow *window;
}

@end

File DirTestAppDelegate.m

#import "DirTestAppDelegate.h"

@implementation DirTestAppDelegate
- (void)applicationDidFinishLaunching:(UIApplication *)application 
{    
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSLog(documentsDirectory);
}


- (void)dealloc 
{
        [super dealloc];
}
@end

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

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

发布评论

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

评论(1

北恋 2024-08-05 08:59:11

这是配置设置不正确的问题。 花了几个小时才修复:-(

It was an issue of the provisioning not set properly. Took hours to fix :-(

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文