0

my problem is that im making a web browser for iPhone/iPad and i tested the bookmarked system and the tableview plist data updates when adding a bookmark. It works on the simulator side But when i tested the app using my iPhone it does not show the updates tableview I did add some data via xcode to the plist and the data i added shows up on the iPhone but still does not update to show new entries that you enter via app the plist file is called "bookmarks.plist" whats the problem ?

Here the code that writes to bookmarks.plist

NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [paths objectAtIndex:0];
NSString *plistPath = [documentDirectory stringByAppendingPathComponent:@"bookmarks.plist"];

if (![fileManager fileExistsAtPath:plistPath]) {
    plistPath = [[NSBundle mainBundle] pathForResource:@"bookmarks" ofType:@"plist"];
    //[[NSFileManager defaultManager] copyItemAtPath:plistPath toPath:plistPath error:NULL];
}

NSMutableArray *dataRoot = [NSMutableArray arrayWithContentsOfFile:plistPath];

NSMutableDictionary *item = [[NSMutableDictionary alloc] init];
[item setObject: _titleField.text forKey:@"title"];
[item setObject:_urlField.text forKey:@"url"];

[dataRoot addObject:item];
[dataRoot writeToFile:plistPath atomically:YES];
Ash-Bash32
  • 423
  • 6
  • 17
  • 1
    Punctuation. Use it, it's good. As for your plist file, are you sure it's not "Bookmarks.plist" or something like that? iOS devices have case-sensitive file system, while iOS Simulator does not if it runs on a Mac with standard drive formatting. – Filip Radelic Dec 02 '12 at 18:53
  • the file in xcode title looks like this "bookmarks.plist" – Ash-Bash32 Dec 02 '12 at 19:12
  • does `plistPath` is populated or nil at runtime when running on device? – Saurabh Passolia Dec 02 '12 at 19:40
  • the plist (plistPath) is empty at start but should fill up when user adds a website to the file – Ash-Bash32 Dec 02 '12 at 19:49

1 Answers1

0

looks like your plist file is not in documents directory on device, neither you are copying it there at runtime (that LOC is commented).

so plistPath will be nil

if your plistPath is created from NSBundle,
[dataRoot writeToFile:plistPath atomically:YES]; file will not be written as bundle resources are read-only.

this info should help you in some way.

Saurabh Passolia
  • 8,099
  • 1
  • 26
  • 41