打包用于临时分发后,iOS 应用程序数据持久性不起作用

发布于 2024-09-28 09:32:54 字数 825 浏览 0 评论 0原文

我刚刚完成了一个应用程序,允许用户在表格视图中存储序列号列表。应用程序存储数字的方式是存储在 NSMutableDictionary 中,然后写入持久性 plist 文件。该应用程序在测试期间运行得非常好。

但是,我刚刚构建并打包了用于临时分发的应用程序,现在当我从最终用户的角度测试应用程序时,数据不会被保存,即当我向表视图添加新行并输入新数字,不会创建新行,也不会向字典中写入任何内容。我使用以下代码写入 plist(假设已经填充了 dict):

[dict writeToFile:[appDelegate dataFilePath] atomically:YES];

在我的应用程序委托中的位置:

- (NSString *)dataFilePath {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    return [documentsDirectory stringByAppendingPathComponent:kFilename];
}

我使用以下命令从磁盘读取 plist:

NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:[appDelegate dataFilePath]];

这里出了什么问题?

I just finished an app that allowed users to store lists of serial numbers in a tableview. The way the app stores the numbers is by storing in an NSMutableDictionary then writing to a persistence plist file. The app ran perfectly fine during testing.

However, I just built and packaged the app for ad-hoc distribution, and now when I test the app from an end-user perspective, the data is not being saved, i.e. when I add a new row to my tableview and typing in a new number, the new row is not being created and nothing is being written to the dictionary. I use the following code to write to the plist (assuming dict is already populated):

[dict writeToFile:[appDelegate dataFilePath] atomically:YES];

where in my App Delegate:

- (NSString *)dataFilePath {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    return [documentsDirectory stringByAppendingPathComponent:kFilename];
}

And I read the plist from disk using this:

NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:[appDelegate dataFilePath]];

What's wrong here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

昨迟人 2024-10-05 09:32:54

如果您说您在持久保存数据时遇到问题,那么您确实应该显示将此 plist 文件写入磁盘的代码,并显示从磁盘加载它的代码。否则,您会要求我们推测性地调试您的代码。

如果您在应用程序包内执行此操作,则这是一个可以在模拟器中运行的操作示例,但不能在设备上运行。

If you say you're having trouble persisting data, you really should show the code where you write this plist file to disk, and also show the code where you load it from disk. Otherwise you're asking us to speculatively debug your code.

If you're doing it inside the application bundle, that is an example of an operation that will work in the Simulator, but not when run on a device.

枕梦 2024-10-05 09:32:54

哦,我意识到一件事。我使用 4.2 beta SDK 完成了所有开发,现在运行使用 4.1 作为基础编译的应用程序,数据似乎不持久! 4.2 中有新的东西可以做到这一点吗?

Oh I realize something. I did all my development using the 4.2 beta SDK and now running the app compiled using 4.1 as the base, the data doesn't seem to persist! Is there something new in 4.2 that does this?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文