在 iPhone 上部署后无法写入 plist 文件
各位。 我面临一个问题。 我可以在 xcode 模拟器上工作时在 plist 上读写。但是当我在 iPhone 中部署该应用程序时,我无法在 plist 上写入。
我创建了一个示例项目,上面有 2 个按钮。通过一键,我可以显示 plist 中的文本。通过第二个按钮,我尝试在该 plist 上写入。但写作并没有发生。单击第二个按钮时应用程序不会崩溃。我无法理解我的代码中的问题。
/*code is given below*/
-(void)writePlist:(NSString *)fname withArray:(NSMutableArray *) myArray
{
NSString * path = nil;
path = [(NSString *) [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:fname];
[myArray writeToFile:path atomically:NO];
}
Dear all.
I am facing a problem.
I can read and write on plist while working on simulator of xcode. but when I deploy the app in iPhone, i can't write on plists.
I have created a sample project having 2 button on it. By one button, I can display the text from plist. By second button, I try to write on that plist. But the writing doesn't happen. The app doesn't crash while clicking on the second button. I can't understand the problem in my code.
/*code is given below*/
-(void)writePlist:(NSString *)fname withArray:(NSMutableArray *) myArray
{
NSString * path = nil;
path = [(NSString *) [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:fname];
[myArray writeToFile:path atomically:NO];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
myArray 变量可能包含不可序列化的对象值(可能是自定义对象或类似的东西)。
It could be that
myArray
variable contains non-serializable object values (probably custom objects or something like that).您尝试写入的目录是否存在?在尝试将文件写入其中之前,您可能需要验证它的存在(如果尚不存在则创建它)。
Does the directory you are trying to write to exist? You may want to verify its existence (and create it if it isn't already there) before trying to write a file into it.