【发布时间】:2011-09-26 00:29:38
【问题描述】:
这段代码的 sn-p 确实在 iPhone 模拟器上运行,但在设备上运行,虽然我正在寻找一个已写入磁盘的文档目录中的文件
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *filepath = [documentsDirectory stringByAppendingString:@"notificationScheduled.plist"];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:filepath];
if (fileExists) {
NSMutableArray *array = [NSMutableArray arrayWithContentsOfFile:filepath];
NSLog(@"%@", array);
[array addObject:date];
[array writeToFile:filepath atomically:YES];
} else {
NSMutableArray *array = [NSMutableArray arrayWithObject:date];
[array writeToFile:filepath atomically:YES];
}
【问题讨论】:
-
你遇到了什么错误?
-
我没有收到任何错误,但第一部分 (if(fileExists) { }) 没有被调用,即使第二次运行它也是如此。它总是做 else 部分,但在模拟器上 if(fileExists) 部分被第二次调用..
-
我可以很好地使用您的代码。您如何验证
if部分未输入? -
使用调试器我看到那部分没有执行
标签: iphone ios-simulator device file-writing