在iPhone上部署后无法写入plist文件 [英] Can't write on plist file after deploying on iPhone

查看:87
本文介绍了在iPhone上部署后无法写入plist文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的. 我正面临一个问题. 在xcode模拟器上工作时,我可以在plist上读写.但是当我在iPhone上部署该应用程序时,我无法写文章.

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.

我创建了一个示例项目,上面有2个按钮.通过一个按钮,我可以显示plist中的文本.通过第二个按钮,我尝试在该plist上书写.但是写作没有发生.单击第二个按钮时,该应用程序不会崩溃.我无法理解我的代码中的问题.

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];   
}

推荐答案

您要写入的目录是否存在?在尝试向其中写入文件之前,您可能需要验证其存在(如果尚未存在,请创建它).

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.

这篇关于在iPhone上部署后无法写入plist文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆