在iOS 5.0.1中写入plists [英] Writing into plists in iOS 5.0.1

查看:73
本文介绍了在iOS 5.0.1中写入plists的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码写入plist:

I am using the following code to write into a plist:

  NSMutableArray *d = [[NSMutableArray alloc] initWithContentsOfFile:
                     [[NSBundle mainBundle] pathForResource:@"FavoritesTaxi" ofType:@"plist"]];
[d addObject:self.dataItem];


// write dictionary to plist
[d writeToFile:[[NSBundle mainBundle] pathForResource:@"FavoritesTaxi" ofType:@"plist"] atomically:YES];
[d release];

我在4个不同的设备(2个模拟器和2个真实的iphone)上测试了这个代码。
它的工作原理如下:
iPhone 4.3模拟器
iPhone 5.0模拟器
iPhone 4.3 Real Device

I tested this code on 4 different devices( 2 simulators and 2 real iphones). It worked on the following : iPhone 4.3 simulator iPhone 5.0 simulator iPhone 4.3 Real Device

但它没有我的工作如下:
iPhone 5.0.1 Real Device。

But it didn't work on the following : iPhone 5.0.1 Real Device.

我真的不知道为什么会发生这种情况。有什么想法吗?它有什么解决方案?

I really do not know why this is happening to this device. Any ideas why? And what is the solution to it?

推荐答案

你不能修改设备上的主捆绑,你没有这样做的特权。所以你不能把一个plist写入主包。我怀疑这对4.3设备有效,它可能没有给你一个错误。

You can't modify the main bundle on the device, you don't have the privileges to do that. So you can't write a plist into the main bundle. I doubt this worked on the 4.3 device, it just may not have given you an error.

您应该将数据保存到文档目录中,这里有大量的代码示例,用于获取文档目录的路径。

You should save data into the documents directory, there are tons of code samples on here for getting a path to the documents directory.

这篇关于在iOS 5.0.1中写入plists的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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