NSSearchPathForDirectoriesInDomains麻烦(快速流失头发) [英] NSSearchPathForDirectoriesInDomains trouble (losing hair fast)
问题描述
我的秃顶很快,需要帮助!
我正在写一个需要访问目录的应用程序。我希望得到一个形式
/ Users / me / Library / Application Support / iPhone Simulator / User / Applications / 6958D21C-C94B-4843-9EF1-70406D0CA3A3 / Documents 的路径。然而,我的应用程序给我 /用户/我/图书馆/应用程序支持/ iPhone模拟器/用户/文档这是不是我想要的因为没有写入权限。
这里是我的代码彻底剥离的版本。请注意,您需要查看模拟器中的控制台以查看输出。我已经检查了我所知道的所有参考,并且没有成功改变这个行为。它是一些编译器选项?或者我必须在Info.plist中更改一些内容?任何人请... ...
更新:对于一些非常奇怪的原因,我的应用程序不是被沙箱。为什么?
文件DirTestAppDelegate.h
#import< UIKit /UIKit.h>
@interface DirTestAppDelegate:NSObject< UIApplicationDelegate>
{
UIWindow *窗口; b
文件DirTestAppDelegate.m p>
#importDirTestAppDelegate.h
@implementation DirTestAppDelegate
- (void)applicationDidFinishLaunching: (UIApplication *)应用程序
{
NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString * documentsDirectory = [paths objectAtIndex:0];
NSLog(documentsDirectory);
$ b - (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
解决方案 It was an issue of the provisioning not set properly. Took hours to fix :-(
这篇关于NSSearchPathForDirectoriesInDomains麻烦(快速流失头发)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!