NSSearchPathForDirectoriesInDomains 麻烦(掉头发快)
我很快就秃顶了,需要帮助!
我正在编写一个需要访问目录的应用程序。 我希望得到一种形式的路径 /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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是配置设置不正确的问题。 花了几个小时才修复:-(
It was an issue of the provisioning not set properly. Took hours to fix :-(