目标c - 由于购买开发者许可证iPhone应用程序无法写入.plist。



我最近支付了99美元的开发许可证,以便能够在iPhone上加载我的应用程序。在此之前,我的应用程序能够在模拟器中将一个简单的"names.plist"文件写入我的应用程序的文档目录。我能够稍后在模拟器中启动该应用程序,并且一些文本将保留在文件中。自从购买许可证并在手机上安装应用程序以来,该应用程序确实会写入模拟器或手机中的沙盒文档目录。似乎开发人员许可证改变了一些东西。

它工作时的代码未更改并正确返回沙盒文档目录。它在下面。我还包含了一个 NSLog 打印,其中包含应用程序现在显示的目录和文件名,具有相同的代码。它适用于名为"Documentsname.plist"的文件,而不是我想要的"names.plist"。我非常感谢任何帮助!谢谢。

//.h
#define username @"name.plist"
// .m -- Define and return this App's sandbox iOS Documents Directory
- (NSString *)userFilePath {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    return [documentsDirectory stringByAppendingFormat:username];
}

尝试写入然后从中读取的路径的 NSLog 如下所示:

/Users/<user>/Library/Application Support/iPhone Simulator/4.3.2/Applications/AF36A4E1-5387-4B10-8F3A-A69AAA307FE4/Documentsname.plist
return [documentsDirectory stringByAppendingPathComponent:username];

您只是附加一个字符串,而不是路径。通过附加"路径组件",它会自动添加/删除需要/不需要的斜杠。

我还建议不要将用户名和".plist"组合在一起。

#define username @"name"
return [[documentsDirectory stringByAppendingPathComponent:username]stringByAppendingString:@".plist"];

简单地添加缺少的"/"怎么样?

#define username @"/name.plist"

相关内容

最新更新